fix: 跳转不存在的路由空白页面问题修复

Former-commit-id: c797a3a474df0d0ec78daafff27f52e47d1d3777
This commit is contained in:
郝先瑞
2022-05-18 23:54:54 +08:00
parent 50c5c1ad2f
commit 14d7d879a0
2 changed files with 14 additions and 6 deletions

View File

@@ -9,7 +9,6 @@ NProgress.configure({ showSpinner: false }); // 进度环显示/隐藏
const whiteList = ['/login', '/auth-redirect'];
router.beforeEach(async (to, from, next) => {
console.log('beforeEach', to);
NProgress.start();
const { user, permission } = useStore();
const hasToken = user.token;
@@ -21,7 +20,11 @@ router.beforeEach(async (to, from, next) => {
} else {
const hasGetUserInfo = user.roles.length > 0;
if (hasGetUserInfo) {
next();
if (to.matched.length === 0) {
from.name ? next({ name: from.name }) : next('/');
} else {
next();
}
} else {
try {
await user.getUserInfo();