You've already forked vue-element-admin
vuex add namespaced
This commit is contained in:
@@ -29,18 +29,18 @@ router.beforeEach((to, from, next) => {
|
||||
if (store.getters.roles.length === 0) {
|
||||
// 判断当前用户是否已拉取完user_info信息
|
||||
store
|
||||
.dispatch('getInfo') // dispatch @/store/modules/user login getInfo
|
||||
.dispatch('user/getInfo')
|
||||
.then(res => {
|
||||
// 拉取user_info
|
||||
const { roles } = res // note: roles must be a object array! such as: [{id: '1', name: 'editor'}, {id: '2', name: 'developer'}]
|
||||
store.dispatch('generateRoutes', { roles }).then(accessRoutes => {
|
||||
store.dispatch('permission/generateRoutes', { roles }).then(accessRoutes => {
|
||||
// 根据roles权限生成可访问的路由表
|
||||
router.addRoutes(accessRoutes) // 动态添加可访问路由表
|
||||
next({ ...to, replace: true }) // hack方法 确保addRoutes已完成 ,set the replace: true so the navigation will not leave a history record
|
||||
})
|
||||
})
|
||||
.catch(err => {
|
||||
store.dispatch('resetToken').then(() => {
|
||||
store.dispatch('user/resetToken').then(() => {
|
||||
Message.error(err)
|
||||
next({ path: '/' })
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user