We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
你好,我这边所有路由均为动态路由,没有固定菜单,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() } } }
The text was updated successfully, but these errors were encountered:
使用 async await
Sorry, something went wrong.
No branches or pull requests
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()
}
}
}
The text was updated successfully, but these errors were encountered: