Normalize legacy home redirects

This commit is contained in:
2026-06-09 18:45:02 +08:00
parent 39aa708c4f
commit f8bdc3e952
6 changed files with 49 additions and 33 deletions
+10 -15
View File
@@ -8,16 +8,10 @@ import { startProgress, stopProgress } from '@vben/utils';
import { accessRoutes, coreRouteNames } from '#/router/routes';
import { useAuthStore } from '#/store';
import { useAppContextStore } from '#/store/app-context';
import { normalizeHomePath } from '#/utils/legacy-home';
import { generateAccess } from './access';
function normalizeHomePath(path?: null | string) {
if (!path || path === '/page-render/main_home') {
return preferences.app.defaultHomePath;
}
return path;
}
/**
* 通用守卫配置
* @param router
@@ -118,9 +112,8 @@ function setupAccessGuard(router: Router) {
// 基本路由,这些路由不需要进入权限拦截
if (coreRouteNames.includes(to.name as string)) {
if (to.path === LOGIN_PATH && accessStore.accessToken) {
return decodeURIComponent(
(to.query?.redirect as string) ||
normalizeHomePath(userStore.userInfo?.homePath),
return normalizeHomePath(
(to.query?.redirect as string) || userStore.userInfo?.homePath,
);
}
return true;
@@ -211,13 +204,15 @@ function setupAccessGuard(router: Router) {
}
// 重定向逻辑
const redirectPath = (from.query.redirect ??
(to.path === preferences.app.defaultHomePath
? normalizeHomePath(userInfo.homePath)
: to.fullPath)) as string;
const redirectPath = normalizeHomePath(
(from.query.redirect ??
(to.path === preferences.app.defaultHomePath
? userInfo.homePath
: to.fullPath)) as string,
);
return {
...router.resolve(decodeURIComponent(redirectPath)),
...router.resolve(redirectPath),
replace: true,
};
});