Vue URL 路由状态未更新但在浏览器中更新

Vue URL Route not updating in state but it does in browser

我正在使用以下代码更改我的 URL:

    this.$router.push({
      path: this.$route.path + this.initialCategoryPath,
    });
    console.log(this.$route.path);

我的URL更改为:www.domain.com/attribute/{{ this.initialCategoryPath content }}

然而,当我记录我的路线时,我仍然只得到 /attribute 部分。

记录当前路线的代码:

console.log(this.$route.path)

谁能帮我解决一下为什么 URL 在路由状态中没有更新,但在 URL 中却更新了?

this.$router.push 方法将新条目推送到 history 堆栈,因此当用户单击浏览器后退按钮时,他们将被带到上一个 URL.

您不需要添加 this.$route.path。这会将您的路线添加到当前路径。

你可以像这样简单地推送:

this.$router.push({ path: this.initialCategoryPath });

更多信息: https://router.vuejs.org/guide/essentials/navigation.html