相关疑难解决方法(0)

vue-router — 未捕获(承诺)错误:通过导航守卫从“/login”重定向到“/”

为什么 vue-router 给我这个错误?需要明确的是,登录流程按预期工作,但我想 a) 摆脱 errro 和 b) 了解错误发生的原因。

错误:

Uncaught (in promise) Error: Redirected from "/login" to "/" via a navigation guard.

登录流程

  1. 开始注销,但输入一个需要身份验证的 URL(即除了“/login”之外的任何内容)
  2. 被重定向到“/login”(如预期的那样)。
  3. 登录
  4. 成功重定向到从步骤 #1 开始的 Url,除了上述错误。

登录操作:

doLogin({ commit }, loginData) {
  commit("loginStart");
  axiosClient
    .post("/jwt-auth/v1/token", {
      username: loginData.username,
      password: loginData.password,
    })
    .then((response) => {
      commit("loginStop", null);
      commit("setUserData", response.data);
      this.categories = airtableQuery.getTable("Categories");
      commit("setCategories", this.categories);
      this.locations = airtableQuery.getTable("Locations");
      commit("setLocations", this.locations);
      router.push("/"); // push to site root after authentication
    })
    .catch((error) => {
      console.log(error.response.data.message);
      commit("loginStop", error.response.data.message);
      commit("delUserData"); …
Run Code Online (Sandbox Code Playgroud)

promise vue.js vue-router

56
推荐指数
5
解决办法
6万
查看次数

标签 统计

promise ×1

vue-router ×1

vue.js ×1