阅遍网,分享的的没一个有效的!!!!
默认前端只写死 以下路由,其他的都由后端给 数据,然后addRouters.
{
path: '/login',
name: 'login',
meta: {
title: 'Login - 登录',
hideInMenu: true
},
component: () => import('@/view/login/login.vue')
},
{
path: '/',
name: 'root',
redirect: '/home',
component: Main,
meta: {
title: '菜单根',
hideInMenu: true,
notCache: true
},
children: [
{
path: '/home',
name: 'home',
meta: {
title: '主页',
hideInMenu: true,
notCache: true
},
component: () => import('@/view/single-page/home')
}
]
},
登录后,addRouters:
let resultRoute = makeRoute(target[0].children)
this.$router.options.routes.push(...resultRoute)
this.$router.addRoutes(resultRoute)
但是,除了默认的/home 可以刷新外。其他的地址,刷新,都卡死了页面,无反应。
即便,你在 守护者那里重新加载了缓存的数据。
// 恢复菜单
if (from.name === null && from.path === '/' && to.path !== '/login') {
let resultRoute = makeRoute(store.state.app.menuAuthList[0].children)
router.options.routes.push(...resultRoute)
router.addRoutes(resultRoute)
}
console.info('routers now:', router.options.routes)
if (token && to.name === LOGIN_PAGE_NAME) {
// 已登录且要跳转的页面是登录页
if (from.name === 'home') {
next(false)
iView.LoadingBar.finish()
} else {
next({
name: 'home' // 跳转到home页
})
}
} else {
next()
输出 router的数据
一切都有啊。我无语。求大神....
自问自答: