Browse Source

feat(router): 添加路由守卫

- 在路由配置中添加了 beforeEach 守卫,用于检查用户登录状态
- 如果用户未登录且目标路由不是登录页,将重定向到登录页
- 移除了部分注释代码,清理了路由配置
master
lizw-2015 6 months ago
parent
commit
1f2e5da4e4
  1. 9
      src/router/index.ts

9
src/router/index.ts

@ -183,4 +183,13 @@ const router = createRouter({
] ]
}) })
router.beforeEach((to, from) => {
if (to.name !== "login" && !window.globalConfig.user) {
return { name: "login" };
}
// if (to.name === "login" && window.globalConfig.user) {
// return { name: "home" };
// }
})
export default router export default router

Loading…
Cancel
Save