修改目录
This commit is contained in:
@@ -2,35 +2,100 @@ import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/demands',
|
||||
name: 'DemandList',
|
||||
component: () => import('../views/DemandList.vue')
|
||||
path: '/dashboard',
|
||||
redirect: '/backend/dashboard'
|
||||
},
|
||||
{
|
||||
path: '/',
|
||||
name: 'Maps',
|
||||
component: () => import('../views/Maps.vue')
|
||||
component: () => import('@/views/index.vue'),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
redirect: '/maps'
|
||||
},
|
||||
{
|
||||
path: 'demands',
|
||||
name: 'DemandList',
|
||||
component: () => import('@/views/index/DemandList.vue')
|
||||
},
|
||||
{
|
||||
path: 'maps',
|
||||
name: 'Maps',
|
||||
component: () => import('@/views/index/Maps.vue')
|
||||
},
|
||||
{
|
||||
path: 'weekly',
|
||||
name: 'WeeklyRecommend',
|
||||
component: () => import('@/views/index/WeeklyRecommend.vue')
|
||||
},
|
||||
{
|
||||
path: 'map/:id',
|
||||
name: 'MapDetail',
|
||||
component: () => import('@/views/index/MapDetail.vue')
|
||||
},
|
||||
{
|
||||
path: 'weapon-match',
|
||||
name: 'WeaponMatch',
|
||||
component: () => import('@/views/index/WeaponMatch.vue')
|
||||
},
|
||||
{
|
||||
path: 'competition',
|
||||
name: 'Competition',
|
||||
component: () => import('@/views/index/Competition.vue')
|
||||
},
|
||||
{
|
||||
path: 'competition/:id',
|
||||
name: 'CompetitionDetail',
|
||||
component: () => import('@/views/index/CompetitionDetail.vue')
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/weekly',
|
||||
name: 'WeeklyRecommend',
|
||||
component: () => import('../views/WeeklyRecommend.vue')
|
||||
},
|
||||
{
|
||||
path: '/map/:id',
|
||||
name: 'MapDetail',
|
||||
component: () => import('../views/MapDetail.vue')
|
||||
},
|
||||
{
|
||||
path: '/weapon-match',
|
||||
name: 'WeaponMatch',
|
||||
component: () => import('../views/WeaponMatch.vue')
|
||||
path: '/backend',
|
||||
component: () => import('@/views/backend.vue'),
|
||||
children: [
|
||||
{
|
||||
path: '',
|
||||
redirect: 'dashboard'
|
||||
},
|
||||
{
|
||||
path: 'login',
|
||||
name: 'Login',
|
||||
component: () => import('@/views/backend/Login.vue')
|
||||
},
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'Dashboard',
|
||||
component: () => import('@/views/backend/Dashboard.vue'),
|
||||
meta: { requiresAuth: true }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
routes,
|
||||
linkActiveClass: 'router-link-active',
|
||||
linkExactActiveClass: 'router-link-exact-active'
|
||||
})
|
||||
|
||||
// 路由守卫
|
||||
router.beforeEach((to, from, next) => {
|
||||
const token = localStorage.getItem('access_token')
|
||||
|
||||
if (to.matched.some(record => record.meta.requiresAuth)) {
|
||||
if (!token) {
|
||||
next({
|
||||
path: '/backend/login',
|
||||
query: { redirect: to.fullPath }
|
||||
})
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user