refactor(router): 优化错误页面路由跳转逻辑

This commit is contained in:
Ray.Hao
2026-05-05 10:46:56 +08:00
parent 36bb4e5499
commit b5e4e4cd15
2 changed files with 7 additions and 1 deletions

View File

@@ -160,7 +160,9 @@ function logout() {
lockScroll: false,
}).then(() => {
userStore.logout().then(() => {
router.push(`/login?redirect=${route.fullPath}`);
// 若当前已在 404/401 等错误页,退出后不再跳回错误页
const redirect = ["/404", "/401"].includes(route.path) ? "/" : route.fullPath;
router.push(`/login?redirect=${encodeURIComponent(redirect)}`);
});
});
}

View File

@@ -56,6 +56,10 @@ export function setupPermissionGuard() {
// 路由 404 检查
if (to.matched.length === 0) {
// 从登录页跳转且目标路径无效,回退首页(避免不同用户权限不同导致的 404
if (_from.path === "/login") {
return { path: "/", replace: true };
}
return "/404";
}