学习资料
学习笔记
一、登录
1. 路由守卫
router.beforeEach((to, from, next) => {const LOGIN_PATH = '/login';const TOKEN_PARAM_NAME = 'token';/*** 🔔🔔🔔 [重点]* 如果用户访问登录页,直接放行* 404 也可以据此直接放行*/if (to.path === LOGIN_PATH) { return next(); }// 从 sessionStorage 中获取保存到的 token 值const tokenStr = window.sessionStorage.getItem(TOKEN_PARAM_NAME);// 无 token ,强制跳转登录页if (!tokenStr) { return next(LOGIN_PATH); }next();});
