1
This commit is contained in:
@@ -43,12 +43,21 @@ export const setupRouterGuards = (router, ViewUI, homeName = 'home') => {
|
||||
}
|
||||
|
||||
if (!token && to.name !== 'login') {
|
||||
// 未登录且访问非登录页 → 跳转到登录页
|
||||
next({ name: 'login' })
|
||||
} else if (!token && to.name === 'login') {
|
||||
// 未登录且访问登录页 → 允许访问
|
||||
next()
|
||||
} else if (token && to.name === 'login') {
|
||||
next({ name: homeName })
|
||||
// 已登录且访问登录页 → 重定向到首页
|
||||
// 避免重复导航警告
|
||||
if (from.name === homeName) {
|
||||
next(false)
|
||||
} else {
|
||||
next({ name: homeName })
|
||||
}
|
||||
} else {
|
||||
// 其他情况 → 允许访问
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user