mirror of
https://github.com/Tencent/tdesign-vue-next-starter.git
synced 2024-09-19 18:24:20 +08:00
perf: 路由守卫获取菜单异常,跳转登录页并弹窗提示 (#502)
This commit is contained in:
parent
4bcf7d22aa
commit
c89f434ce8
|
@ -25,38 +25,37 @@ router.beforeEach(async (to, from, next) => {
|
|||
}
|
||||
try {
|
||||
await userStore.getUserInfo();
|
||||
|
||||
const { asyncRoutes } = permissionStore;
|
||||
|
||||
if (asyncRoutes && asyncRoutes.length === 0) {
|
||||
const routeList = await permissionStore.buildAsyncRoutes();
|
||||
routeList.forEach((item: RouteRecordRaw) => {
|
||||
router.addRoute(item);
|
||||
});
|
||||
|
||||
if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
|
||||
// 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容
|
||||
next({ path: to.fullPath, replace: true, query: to.query });
|
||||
} else {
|
||||
const redirect = decodeURIComponent((from.query.redirect || to.path) as string);
|
||||
next(to.path === redirect ? { ...to, replace: true } : { path: redirect });
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (router.hasRoute(to.name)) {
|
||||
next();
|
||||
} else {
|
||||
next(`/`);
|
||||
}
|
||||
} catch (error) {
|
||||
MessagePlugin.error(error);
|
||||
MessagePlugin.error(error.message);
|
||||
next({
|
||||
path: '/login',
|
||||
query: { redirect: encodeURIComponent(to.fullPath) },
|
||||
});
|
||||
NProgress.done();
|
||||
}
|
||||
|
||||
const { asyncRoutes } = permissionStore;
|
||||
|
||||
if (asyncRoutes && asyncRoutes.length === 0) {
|
||||
const routeList = await permissionStore.buildAsyncRoutes();
|
||||
routeList.forEach((item: RouteRecordRaw) => {
|
||||
router.addRoute(item);
|
||||
});
|
||||
|
||||
if (to.name === PAGE_NOT_FOUND_ROUTE.name) {
|
||||
// 动态添加路由后,此处应当重定向到fullPath,否则会加载404页面内容
|
||||
next({ path: to.fullPath, replace: true, query: to.query });
|
||||
} else {
|
||||
const redirect = decodeURIComponent((from.query.redirect || to.path) as string);
|
||||
next(to.path === redirect ? { ...to, replace: true } : { path: redirect });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (router.hasRoute(to.name)) {
|
||||
next();
|
||||
} else {
|
||||
next(`/`);
|
||||
}
|
||||
} else {
|
||||
/* white list router */
|
||||
if (whiteListRouters.indexOf(to.path) !== -1) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user