|
@@ -1,4 +1,4 @@
|
|
|
-import router, { selfAddRoutes } from './router'
|
|
|
|
|
|
|
+import router, { selfAddRoutes, resetRouter } from './router'
|
|
|
import store from './store'
|
|
import store from './store'
|
|
|
import { Message } from 'element-ui'
|
|
import { Message } from 'element-ui'
|
|
|
import NProgress from 'nprogress' // progress bar
|
|
import NProgress from 'nprogress' // progress bar
|
|
@@ -28,6 +28,7 @@ router.beforeEach(async(to, from, next) => {
|
|
|
} else {
|
|
} else {
|
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
// determine whether the user has obtained his permission roles through getInfo
|
|
|
const hasRoles = store.getters.roles && store.getters.roles.length > 0
|
|
const hasRoles = store.getters.roles && store.getters.roles.length > 0
|
|
|
|
|
+ // const hasRoles = localStorage.getItem('accessToken')
|
|
|
if (hasRoles) {
|
|
if (hasRoles) {
|
|
|
next()
|
|
next()
|
|
|
} else {
|
|
} else {
|
|
@@ -36,14 +37,12 @@ router.beforeEach(async(to, from, next) => {
|
|
|
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
|
|
// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
|
|
|
// const { roles } = await store.dispatch('user/getInfo')
|
|
// const { roles } = await store.dispatch('user/getInfo')
|
|
|
const { roles } = ['admin'];
|
|
const { roles } = ['admin'];
|
|
|
-
|
|
|
|
|
|
|
+ resetRouter()
|
|
|
// generate accessible routes map based on roles
|
|
// generate accessible routes map based on roles
|
|
|
const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
|
|
const accessRoutes = await store.dispatch('permission/generateRoutes', roles)
|
|
|
// dynamically add accessible routes
|
|
// dynamically add accessible routes
|
|
|
- console.log(accessRoutes)
|
|
|
|
|
- selfAddRoutes(accessRoutes)
|
|
|
|
|
|
|
+ router.addRoutes(accessRoutes)
|
|
|
// selfAddRoutes(accessRoutes)
|
|
// selfAddRoutes(accessRoutes)
|
|
|
-
|
|
|
|
|
// hack method to ensure that addRoutes is complete
|
|
// hack method to ensure that addRoutes is complete
|
|
|
// set the replace: true, so the navigation will not leave a history record
|
|
// set the replace: true, so the navigation will not leave a history record
|
|
|
next({ ...to, replace: true })
|
|
next({ ...to, replace: true })
|