diff --git a/web/src/permission.js b/web/src/permission.js index 7d53caab..91caab56 100644 --- a/web/src/permission.js +++ b/web/src/permission.js @@ -5,13 +5,26 @@ let asyncRouterFlag = 0 const whiteList = ['Login', 'Init'] +const getRouter = async() => { + await store.dispatch('router/SetAsyncRouter') + await store.dispatch('user/GetUserInfo') + const asyncRouters = store.getters['router/asyncRouters'] + asyncRouters.map(asyncRouter => { + router.addRoute(asyncRouter) + }) +} + router.beforeEach(async(to, from, next) => { const token = store.getters['user/token'] // 在白名单中的判断情况 document.title = getPageTitle(to.meta.title) if (whiteList.indexOf(to.name) > -1) { if (token) { - next({ path: '/layout/dashboard' }) + if (!asyncRouterFlag) { + asyncRouterFlag++ + await getRouter() + } + next({ name: store.getters['user/userInfo'].authority.defaultRouter }) } else { next() } @@ -21,15 +34,14 @@ router.beforeEach(async(to, from, next) => { // 添加flag防止多次获取动态路由和栈溢出 if (!asyncRouterFlag) { asyncRouterFlag++ - await store.dispatch('router/SetAsyncRouter') - await store.dispatch('user/GetUserInfo') - const asyncRouters = store.getters['router/asyncRouters'] - asyncRouters.map(asyncRouter => { - router.addRoute(asyncRouter) - }) + await getRouter() next({ ...to, replace: true }) } else { - next() + if (to.matched.length) { + next() + } else { + next({ path: '/layout/404' }) + } } } // 不在白名单中并且未登陆的时候 diff --git a/web/src/store/module/user.js b/web/src/store/module/user.js index b14f68e5..e836a327 100644 --- a/web/src/store/module/user.js +++ b/web/src/store/module/user.js @@ -11,7 +11,7 @@ export const user = { uuid: '', nickName: '', headerImg: '', - authority: '', + authority: {}, sideMode: 'dark', activeColor: '#1890ff', baseColor: '#fff'