chore: 先验证token,再获取菜单 (#487)

This commit is contained in:
liweijie0812 2023-05-08 22:15:59 +08:00 committed by GitHub
parent a0c67b05d9
commit 0d70db425d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -23,6 +23,16 @@ router.beforeEach(async (to, from, next) => {
next(); next();
return; return;
} }
try {
await userStore.getUserInfo();
} catch (error) {
MessagePlugin.error(error);
next({
path: '/login',
query: { redirect: encodeURIComponent(to.fullPath) },
});
NProgress.done();
}
const { asyncRoutes } = permissionStore; const { asyncRoutes } = permissionStore;
@ -42,21 +52,10 @@ router.beforeEach(async (to, from, next) => {
} }
} }
try { if (router.hasRoute(to.name)) {
await userStore.getUserInfo(); next();
} else {
if (router.hasRoute(to.name)) { next(`/`);
next();
} else {
next(`/`);
}
} catch (error) {
MessagePlugin.error(error);
next({
path: '/login',
query: { redirect: encodeURIComponent(to.fullPath) },
});
NProgress.done();
} }
} else { } else {
/* white list router */ /* white list router */