Vue路由守卫

router.beforeEach((to, from, next) => {
 let user_name = localStorage.getItem('user_name')
 if (to.path === '/') {
  next()
  return
 } else {
  if (user_name === null || user_name === '') {
   alert('您暂未登录,请先登录')
   next('/')
  } else {
   next()
  }
 }
})

 

posted @ 2021-04-15 17:17  yw3692582  阅读(30)  评论(0编辑  收藏  举报