1
2
3
4
5
6
7
8
9
10
router.beforeEach((to, from, next) => {
const token = window.sessionStorage.getItem('token')
if (to.fullPath !== '/login' && !token) {
console.log('no token,please login.')
next('/login')
}
// 如果用户未能验证身份,则 `next` 会被调用两次
next()
})