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"
      });
    }
  }
});


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM