fixed:#1336 (#1337)

This commit is contained in:
奇淼(piexlmax
2023-01-14 10:27:07 +08:00
committed by GitHub
parent 24215f8b28
commit dfcb283899
2 changed files with 6 additions and 6 deletions

View File

@@ -4,8 +4,6 @@ import getPageTitle from '@/utils/page'
import router from '@/router'
import Nprogress from 'nprogress'
let asyncRouterFlag = 0
const whiteList = ['Login', 'Init']
const getRouter = async(userStore) => {
@@ -38,6 +36,7 @@ async function handleKeepAlive(to) {
}
router.beforeEach(async(to, from) => {
const routerStore = useRouterStore()
Nprogress.start()
const userStore = useUserStore()
to.meta.matched = [...to.matched]
@@ -47,8 +46,7 @@ router.beforeEach(async(to, from) => {
document.title = getPageTitle(to.meta.title, to)
if (whiteList.indexOf(to.name) > -1) {
if (token) {
if (!asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
asyncRouterFlag++
if (!routerStore.asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
await getRouter(userStore)
}
// token 可以解析但是却是不存在的用户 id 或角色 id 会导致无限调用
@@ -71,8 +69,7 @@ router.beforeEach(async(to, from) => {
// 不在白名单中并且已经登录的时候
if (token) {
// 添加flag防止多次获取动态路由和栈溢出
if (!asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
asyncRouterFlag++
if (!routerStore.asyncRouterFlag && whiteList.indexOf(from.name) < 0) {
await getRouter(userStore)
if (userStore.token) {
return { ...to, replace: true }