fix(auth): 登录页守卫对登出/切号导航放行判断改读 to.query
window.location.search 在守卫执行时仍是旧地址,会漏判 /home 点击"退出"的 router-link 导致登出无效果;改为判断路由目标 query 的 logout/switch 参数。
This commit is contained in:
@@ -22,10 +22,17 @@ router.beforeEach(async (to) => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
router.beforeEach((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')) {
|
if (to.name === 'login' && window.localStorage.getItem('uid')) {
|
||||||
const logout = String(window.location.search).includes('logout=1')
|
const isLogoutNav = to.query.logout === '1' || to.query.switch === '1'
|
||||||
if (!logout) return { name: 'home' }
|
if (isLogoutNav) {
|
||||||
|
// 排查日志:登出/切号放行(清 token 逻辑在登录页 onMounted 处理)
|
||||||
|
console.log('[auth] 登出导航放行, fullPath=', to.fullPath)
|
||||||
|
} else {
|
||||||
|
return { name: 'home' }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
})
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user