关于导航守卫问题 (判断有没有token )

router.beforeEach((to, from, next) => {

  let authUrlArr = ["/home/list", "/home/publish"];

  let token = localStorage.getItem("token");

  if (authUrlArr.includes(to.path)) {

    // 进一步判断

    if (token) {

      next();

    } else {

      next("/login");

    }

  } else {

    next();

  }

});

你可能感兴趣的:(关于导航守卫问题 (判断有没有token ))