Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

所有路由均为动态路由,没有固定菜单~ #3810

Open
adozhao opened this issue Sep 8, 2021 · 1 comment
Open

所有路由均为动态路由,没有固定菜单~ #3810

adozhao opened this issue Sep 8, 2021 · 1 comment

Comments

@adozhao
Copy link

adozhao commented Sep 8, 2021

Question(提问)

你好,我这边所有路由均为动态路由,没有固定菜单,router/index.js中的 path:‘/’ 的路由要跳转的方向应该是addRouters路由后的第一个路由,然而此时直接从store获取由于时机问题是获取不到的, 想问问老哥这里应该怎么处理。搞一天了都~~~

//router/index.js
{
path: '/',
component: Layout,
redirect: '',
// redirect: store.getters.addRouters[0].path, //undefined
name: 'Layout',
hidden: true
},

//permisson.js
if (getToken()) {
if (to.path === '/login') {
next({ path: '/' })
NProgress.done()
} else{
if (store.getters.roles.length === 0) {
store.dispatch('GetInfo').then(res => {
// console.log('res.data.roles~~~',res.data.roles)
const roles = res.data.role.toString() // ['editor','develop']
store.dispatch('GenerateRoutes', [roles]).then(() => { // 根据roles权限生成可访问的路由表
router.addRoutes(store.getters.addRouters) // 动态添加可访问路由表
// sessionStorage.setItem('DefaultPath', store.getters.addRouters[0].path)
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成
})
}).catch((err) => {
store.dispatch('FedLogOut').then(() => {
Message.error(err || 'Verification failed, please login again')
next({ path: '/' })
})
})
} else {
next()
}
}
}

@moyulx
Copy link

moyulx commented Sep 23, 2021

使用 async await

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants