vue-router 导航守卫

126 阅读1分钟
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()
})