加入路由守卫和退出系统功能。

This commit is contained in:
2023-01-11 18:13:39 +08:00
parent 4ecbc2e630
commit d995251d7b
8 changed files with 128 additions and 23 deletions

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2022-12-14 15:12:46
* @LastEditors: Kane
* @LastEditTime: 2023-01-07 11:54:38
* @LastEditTime: 2023-01-11 10:28:24
* @FilePath: \admin_system\src\router\index.js
* @Description: 定义应用路由配置
*
@@ -15,7 +15,7 @@ const routes = [
{
path: "/",
name: "Root",
redirect: "Home",
redirect: "Login", //默认路由指向登录页面
hidden: true,
},
{
@@ -99,4 +99,22 @@ const router = createRouter({
routes
});
//前置路由守卫
router.beforeEach((to) =>
{
const token = window.localStorage.getItem("token");
if (!token)
{
//如果token不存在判断路由是否走向login,如果不是则指向login
//走向login则不干预
if (to.name !== "Login")
{
return {
name: "Login",
};
}
}
});
export default router;