feat(登录): 添加路由守卫和异步导航处理
fix(表单验证): 为用户、角色和菜单管理添加表单验证规则 test(e2e): 增加页面导航超时时间和网络空闲等待 refactor(数据库): 移除Flyway配置并更新数据源配置
This commit is contained in:
@@ -76,4 +76,27 @@ const router = createRouter({
|
||||
routes
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
try {
|
||||
const token = localStorage.getItem('token')
|
||||
|
||||
if (to.path === '/login') {
|
||||
if (token) {
|
||||
next('/')
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
} else {
|
||||
if (token) {
|
||||
next()
|
||||
} else {
|
||||
next('/login')
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('路由守卫错误:', error)
|
||||
next('/login')
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
|
||||
Reference in New Issue
Block a user