Browse Source

Merge pull request #691 from flipped-aurora/gva-vue3

修复在登录状态下访问白名单路由导致白屏的bug
main
奇淼(piexlmax 3 years ago
committed by GitHub
parent
commit
45f1d4bd65
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 28
      web/src/permission.js
  2. 2
      web/src/store/module/user.js

28
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' })
}
}
}
// 不在白名单中并且未登陆的时候

2
web/src/store/module/user.js

@ -11,7 +11,7 @@ export const user = {
uuid: '',
nickName: '',
headerImg: '',
authority: '',
authority: {},
sideMode: 'dark',
activeColor: '#1890ff',
baseColor: '#fff'

Loading…
Cancel
Save