From b5e4e4cd15cc0dc55226a99b9686c017c2517e3a Mon Sep 17 00:00:00 2001 From: "Ray.Hao" <1490493387@qq.com> Date: Tue, 5 May 2026 10:46:56 +0800 Subject: [PATCH] =?UTF-8?q?refactor(router):=20=E4=BC=98=E5=8C=96=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E9=A1=B5=E9=9D=A2=E8=B7=AF=E7=94=B1=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/components/LayoutToolbar.vue | 4 +++- src/router/guards/permission.ts | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/layouts/components/LayoutToolbar.vue b/src/layouts/components/LayoutToolbar.vue index c829c3fa..23bb5f81 100644 --- a/src/layouts/components/LayoutToolbar.vue +++ b/src/layouts/components/LayoutToolbar.vue @@ -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)}`); }); }); } diff --git a/src/router/guards/permission.ts b/src/router/guards/permission.ts index 5de45807..4685be0b 100644 --- a/src/router/guards/permission.ts +++ b/src/router/guards/permission.ts @@ -56,6 +56,10 @@ export function setupPermissionGuard() { // 路由 404 检查 if (to.matched.length === 0) { + // 从登录页跳转且目标路径无效,回退首页(避免不同用户权限不同导致的 404) + if (_from.path === "/login") { + return { path: "/", replace: true }; + } return "/404"; }