fix: 修复登录状态下还能访问白名单路由问题

This commit is contained in:
lww9029 2026-10-13 10:36:25 +08:00
parent 4aa63baf75
commit dc581d7185

View file

@ -197,16 +197,22 @@ const anonRouteNames = new Set(['login', 'Register', 'RetrievePassword', 'welcom
// 路由守卫 // 路由守卫
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
if (anonRouteNames.has(to.name)) { const token = localStorage.getItem('token');
next() const isAnonRoute = anonRouteNames.has(to.name);
if (isAnonRoute && token) {
next({ name: 'home', replace: true })
return return
} }
// 非白名单路由必须登录
const token = localStorage.getItem('token') if (!isAnonRoute && !token) {
if (!token) { next({
next({ name: 'login' }) name: 'login',
replace: true
})
return return
} }
next() next()
}) })