Vue 3 嵌套路由

时间:2021-03-25 17:01:02

标签: vue.js vuejs3 vue-router4

给定以下路线:

{
path: '/detail/:someId',
component: SomeDetailComponent,
name: 'some-detail',
children: [
  {
    path: 'dashboard',
    component: DashboardComponent,
    name: 'dashboard'
  },
  {
    path: '',
    redirect: { name: 'dashboard' }
  },
  {
    path: 'other',
    component: OtherComponent,
    name: 'other'
  }
]

},

为什么这样做(仪表板组件可见):

this.$router.push(`/detail/123/`);

但这不会:

this.$router.push({name: 'some-detail', params: { someId: 123 }});

在一种情况下,URL 带有尾部斜杠,而在另一种情况下则没有。我在文档中的某处读到,这是来自 Vue2 的重大更改。看: named-children-routes-with-an-empty-path-no-longer-appends-a-slash

所以这里真正的问题可能是:如何在仍然能够使用路由名称而不是路由 url 部分进行导航的同时,仍然拥有我的工作子导航(带重定向)。

0 个答案:

没有答案