From 3f599547e6fb2b737dbd2ee8ce2b2c25cb20e220 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=BB=84=E8=87=AA=E8=BE=BE?= <980324341@qq.com> Date: Tue, 8 Sep 2026 22:30:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(auth):=20=E7=99=BB=E5=BD=95=E9=A1=B5?= =?UTF-8?q?=E5=AE=88=E5=8D=AB=E5=AF=B9=E7=99=BB=E5=87=BA/=E5=88=87?= =?UTF-8?q?=E5=8F=B7=E5=AF=BC=E8=88=AA=E6=94=BE=E8=A1=8C=E5=88=A4=E6=96=AD?= =?UTF-8?q?=E6=94=B9=E8=AF=BB=20to.query?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit window.location.search 在守卫执行时仍是旧地址,会漏判 /home 点击"退出"的 router-link 导致登出无效果;改为判断路由目标 query 的 logout/switch 参数。 --- frontend-vue/src/main.ts | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/frontend-vue/src/main.ts b/frontend-vue/src/main.ts index ab3dca78..3c5d5d1c 100644 --- a/frontend-vue/src/main.ts +++ b/frontend-vue/src/main.ts @@ -22,10 +22,17 @@ router.beforeEach(async (to) => { }) router.beforeEach((to) => { - // 已登录访问登录页 → 回首页(与 MPA 时代 login.html 展示"请先退出"一致:直接回首页) + // 已登录访问登录页 → 回首页(与 MPA 时代 login.html 展示"请先退出"一致:直接回首页); + // 但带 logout/switch 的登出导航放行。判断须看 to.query:守卫在 URL 更新前执行, + // window.location.search 仍是旧地址,会漏判 /home 点击"退出"的 router-link(=登出无效果)。 if (to.name === 'login' && window.localStorage.getItem('uid')) { - const logout = String(window.location.search).includes('logout=1') - if (!logout) return { name: 'home' } + const isLogoutNav = to.query.logout === '1' || to.query.switch === '1' + if (isLogoutNav) { + // 排查日志:登出/切号放行(清 token 逻辑在登录页 onMounted 处理) + console.log('[auth] 登出导航放行, fullPath=', to.fullPath) + } else { + return { name: 'home' } + } } return true })