【问题标题】:How to programmatically go to the previous route in vue-router?如何以编程方式转到 vue-router 中的上一条路线?
【发布时间】:2019-08-25 16:04:41
【问题描述】:

如何在 vue-router 中以编程方式导航到父路由。

$router.go(-1)

有效,但它会将我发送到之前访问过的路线。

我希望目的地是父路由。

【问题讨论】:

  • 如果你在/photos/photo123,你想要一个能把你带到/photos的功能?
  • 使用 $route.matched,它会给你一个包含你需要的对象(应该在第一个索引)

标签: vue.js vue-router


【解决方案1】:

导航到父路由:

this.$router.push(this.$route.matched[1].parent.path)

这仅适用于我的情况。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-11-24
    • 1970-01-01
    • 1970-01-01
    • 2021-05-03
    • 1970-01-01
    • 2015-06-18
    相关资源
    最近更新 更多