|
@@ -8,6 +8,7 @@ import { useUserStoreWithOut } from '/@/store/modules/user';
|
|
|
import { PAGE_NOT_FOUND_ROUTE } from '/@/router/routes/basic';
|
|
|
|
|
|
import { RootRoute } from '/@/router/routes';
|
|
|
+import { omit } from 'lodash-es';
|
|
|
|
|
|
const LOGIN_PATH = PageEnum.BASE_LOGIN;
|
|
|
|
|
@@ -18,26 +19,20 @@ const whitePathList: PageEnum[] = [LOGIN_PATH];
|
|
|
export function createPermissionGuard(router: Router) {
|
|
|
const userStore = useUserStoreWithOut();
|
|
|
const permissionStore = usePermissionStoreWithOut();
|
|
|
- router.beforeEach(async (to, from, next) => {
|
|
|
- // Jump to the 404 page after processing the login
|
|
|
- if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name) {
|
|
|
- next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
+ router.beforeEach(async (to, from) => {
|
|
|
if (
|
|
|
from.path === ROOT_PATH &&
|
|
|
to.path === PageEnum.BASE_HOME &&
|
|
|
userStore.getUserInfo.homePath &&
|
|
|
userStore.getUserInfo.homePath !== PageEnum.BASE_HOME
|
|
|
) {
|
|
|
- next(userStore.getUserInfo.homePath);
|
|
|
- return;
|
|
|
+ // next(userStore.getUserInfo.homePath);
|
|
|
+ return userStore.getUserInfo.homePath;
|
|
|
}
|
|
|
|
|
|
// Whitelist can be directly entered
|
|
|
if (whitePathList.includes(to.path as PageEnum)) {
|
|
|
- next();
|
|
|
+ // next();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -47,7 +42,7 @@ export function createPermissionGuard(router: Router) {
|
|
|
if (!token) {
|
|
|
// You can access without permission. You need to set the routing meta.ignoreAuth to true
|
|
|
if (to.meta.ignoreAuth) {
|
|
|
- next();
|
|
|
+ // next();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -62,12 +57,18 @@ export function createPermissionGuard(router: Router) {
|
|
|
redirect: to.path,
|
|
|
};
|
|
|
}
|
|
|
- next(redirectData);
|
|
|
- return;
|
|
|
+ //next(redirectData);
|
|
|
+ return redirectData;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Jump to the 404 page after processing the login
|
|
|
+ if (from.path === LOGIN_PATH && to.name === PAGE_NOT_FOUND_ROUTE.name) {
|
|
|
+ //next(userStore.getUserInfo.homePath || PageEnum.BASE_HOME);
|
|
|
+ return userStore.getUserInfo.homePath || PageEnum.BASE_HOME;
|
|
|
}
|
|
|
|
|
|
if (permissionStore.getIsDynamicAddedRoute) {
|
|
|
- next();
|
|
|
+ // next();
|
|
|
return;
|
|
|
}
|
|
|
|
|
@@ -79,8 +80,12 @@ export function createPermissionGuard(router: Router) {
|
|
|
|
|
|
const redirectPath = (from.query.redirect || to.path) as string;
|
|
|
const redirect = decodeURIComponent(redirectPath);
|
|
|
- const nextData = to.path === redirect ? { ...to, replace: true } : { path: redirect };
|
|
|
+ const nextData =
|
|
|
+ to.path === redirect
|
|
|
+ ? { ...omit(to, ['name', 'params']), replace: true }
|
|
|
+ : { path: redirect };
|
|
|
permissionStore.setDynamicAddedRoute(true);
|
|
|
- next(nextData);
|
|
|
+ // next(nextData);
|
|
|
+ return nextData;
|
|
|
});
|
|
|
}
|