//挂载路由导航守卫
router.beforeEach((to, from, next) => {
// to 将要访问的路径
// from 代表从哪个路径过来
// next 是一个函数,表示放行
if(to.path==='/login') return next()
// 获取token
const tokenStr=window.sessionStorage.getItem('token')
if (!tokenStr) return next('/login')
next()
})
08-06
288
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
10-19
289
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-23
369
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-14
08-14