vue 路由守卫是否携带token

  //整个实例出来     配置路由守卫 
 const router = new Router({
   //这里面是路由配置哈
 }) 


 router.beforeEach((to, from, next) => {
  if (to.path == "/login") {
    next();
  } else {
    const token = localStorage.getItem("token");
    if (token) {
      next();
    } else {
      router.push({
        name: "login"
      });
    }
  }
});
原文地址:https://www.cnblogs.com/IwishIcould/p/12445273.html