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 })