美文网首页Vue
vue路由守卫-判断有没有登陆

vue路由守卫-判断有没有登陆

作者: hello_web_Front | 来源:发表于2020-08-12 17:00 被阅读0次
    let isLogin = window.localStorage.getItem('token');
    
    router.beforeEach((to, from, next) => {
    
      if (isLogin) {
        // 如果存在token 放行
        next()
      } else {
        //如果用户token不存在且 当前页面就是登陆 则放行
        if (to.path === '/noauth') {
          next()
        } else {
          // 当前页面不是登录页 则直接跳转到登陆页面
          next('/noauth')
        }
      }
    })
    

    相关文章

      网友评论

        本文标题:vue路由守卫-判断有没有登陆

        本文链接:https://www.haomeiwen.com/subject/ikdmdktx.html