router.beforeEach((to, from, next) => {
if(to.path != "/login" && store.getters.menu.length == 0 && store.getters.access_token){
store.dispatch('GetMenu').then((res) => {
if(res){
for (let index = 0; index < res.length; index++) {
res[index].component = () => import('@/' + res[index].routeView)
}
router.addRoutes([
{
path: '/',
redirect: '/dashboard',
component: () => import('@/views/dashboard/Index'),
children: res
}
])
router.addRoutes([
{
path: '*', // 页面不存在的情况下会跳到404页面
redirect: '/404',
}
])
}
})
}
vue路由动态配置
最新推荐文章于 2023-12-18 22:28:51 发布