init
This commit is contained in:
101
admin/src/router/index.js
Normal file
101
admin/src/router/index.js
Normal file
@@ -0,0 +1,101 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'Login',
|
||||
component: () => import('@/views/Login.vue'),
|
||||
meta: { requiresAuth: false }
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
component: () => import('@/layout/index.vue'),
|
||||
redirect: '/dashboard',
|
||||
meta: { requiresAuth: true },
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
component: () => import('@/views/Dashboard.vue'),
|
||||
meta: { title: '仪表盘', icon: 'DataBoard' }
|
||||
},
|
||||
{
|
||||
path: 'users',
|
||||
name: 'Users',
|
||||
component: () => import('@/views/users/index.vue'),
|
||||
meta: { title: '用户管理', icon: 'User' }
|
||||
},
|
||||
{
|
||||
path: 'products',
|
||||
name: 'ProductList',
|
||||
component: () => import('@/views/products/ProductList.vue'),
|
||||
meta: { title: '商品管理', icon: 'Goods' }
|
||||
},
|
||||
{
|
||||
path: 'products/categories',
|
||||
name: 'Categories',
|
||||
component: () => import('@/views/products/categories.vue'),
|
||||
meta: { title: '商品分类', icon: 'Goods' }
|
||||
},
|
||||
{
|
||||
path: 'orders',
|
||||
name: 'Orders',
|
||||
component: () => import('@/views/orders/index.vue'),
|
||||
meta: { title: '订单管理', icon: 'Document' }
|
||||
},
|
||||
{
|
||||
path: 'refunds',
|
||||
name: 'Refunds',
|
||||
component: () => import('@/views/refunds/index.vue'),
|
||||
meta: { title: '退款管理', icon: 'RefreshLeft' }
|
||||
},
|
||||
{
|
||||
path: 'banners',
|
||||
name: 'Banners',
|
||||
component: () => import('@/views/banners/index.vue'),
|
||||
meta: { title: '轮播图管理', icon: 'Picture' }
|
||||
},
|
||||
{
|
||||
path: 'system',
|
||||
name: 'System',
|
||||
component: () => import('@/views/system/index.vue'),
|
||||
meta: { title: '系统管理', icon: 'Setting' },
|
||||
children: [
|
||||
{
|
||||
path: 'roles',
|
||||
name: 'Roles',
|
||||
component: () => import('@/views/system/Roles.vue'),
|
||||
meta: { title: '角色管理' }
|
||||
},
|
||||
{
|
||||
path: 'permissions',
|
||||
name: 'Permissions',
|
||||
component: () => import('@/views/system/Permissions.vue'),
|
||||
meta: { title: '权限管理' }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
})
|
||||
|
||||
// 路由守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
const authStore = useAuthStore()
|
||||
|
||||
if (to.meta.requiresAuth && !authStore.isAuthenticated) {
|
||||
next('/login')
|
||||
} else if (to.path === '/login' && authStore.isAuthenticated) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user