82 lines
2.1 KiB
TypeScript
82 lines
2.1 KiB
TypeScript
import { createRouter, createWebHistory } from 'vue-router'
|
|
|
|
const router = createRouter({
|
|
history: createWebHistory(),
|
|
routes: [
|
|
{
|
|
path: '/login',
|
|
name: 'Login',
|
|
component: () => import('../views/Login.vue'),
|
|
},
|
|
{
|
|
path: '/',
|
|
component: () => import('../layout/AdminLayout.vue'),
|
|
redirect: '/dashboard',
|
|
meta: { requiresAuth: true },
|
|
children: [
|
|
{
|
|
path: 'dashboard',
|
|
name: 'Dashboard',
|
|
component: () => import('../views/Dashboard.vue'),
|
|
},
|
|
{
|
|
path: 'products',
|
|
name: 'ProductList',
|
|
component: () => import('../views/product/ProductList.vue'),
|
|
},
|
|
{
|
|
path: 'products/create',
|
|
name: 'ProductCreate',
|
|
component: () => import('../views/product/ProductForm.vue'),
|
|
},
|
|
{
|
|
path: 'products/:id/edit',
|
|
name: 'ProductEdit',
|
|
component: () => import('../views/product/ProductForm.vue'),
|
|
},
|
|
{
|
|
path: 'orders',
|
|
name: 'OrderList',
|
|
component: () => import('../views/order/OrderList.vue'),
|
|
},
|
|
{
|
|
path: 'molds',
|
|
name: 'MoldList',
|
|
component: () => import('../views/mold/MoldList.vue'),
|
|
},
|
|
{
|
|
path: 'categories',
|
|
name: 'CategoryList',
|
|
component: () => import('../views/category/CategoryList.vue'),
|
|
},
|
|
{
|
|
path: 'settings',
|
|
name: 'Settings',
|
|
component: () => import('../views/settings/ShippingNotice.vue'),
|
|
},
|
|
{
|
|
path: 'users',
|
|
name: 'UserList',
|
|
component: () => import('../views/user/UserList.vue'),
|
|
},
|
|
{
|
|
path: 'gold-price',
|
|
name: 'GoldPrice',
|
|
component: () => import('../views/settings/GoldPrice.vue'),
|
|
},
|
|
],
|
|
},
|
|
],
|
|
})
|
|
|
|
router.beforeEach((to, _from, next) => {
|
|
const token = localStorage.getItem('admin_token')
|
|
if (to.matched.some((r) => r.meta.requiresAuth) && !token) {
|
|
next('/login')
|
|
} else {
|
|
next()
|
|
}
|
|
})
|
|
|
|
export default router
|