【问题标题】:Vue- router view lost the param when routing to the childrenVue-路由器视图在路由到孩子时丢失了参数
【发布时间】:2018-11-26 09:02:26
【问题描述】:

我使用 I 路由器在组件之间进行路由 我使用子路由在页面中路由,但我丢失了我在父级中传递的参数

这是我的路由器定义:

export default new Router({
  mode: 'history',
  routes: [
    {
      path: '/management', name: 'Management', component: Management,
      children: [
        {
          path: '/managementFlow/:confType',
          component: ManagementFlow,
          children: [
            {
              path: '/listConfiguration/:type',
              component: ListConfiguration,
              props: true
            },
            {
              path: '/bulkConfiguration/:type',
              component: BulkConfiguration,
              props: true
            },
          ],
          props: true,
        },
      ]
    },
  ],
})

当我与父级一起使用时 - to:"/managementFlow/myConfType" 我得到了 confType。 我在 props 中得到值:["confType"],

但是当我将父级路由到子级时,我丢失了参数 confType

pathForRouting = `/listConfiguration/${this.type}`;
this.$router.push({
        path: pathForRouting
      });

我只在孩子身上得到参数: 道具:[“类型”],

【问题讨论】:

  • 你孩子的完整路径是什么? /management/managementFlow/:confType/listConfiguration/:type?
  • 对,这是全名,但在链接中我只看到 /listConfiguration/MyType
  • 如果我可以为 confType 和 type 使用相同的值,我是一个解决方案,如果我将名称更改为相同 - 敌人示例:confType to type,它会很好用
  • “但是当我在父节点路由到子节点时”——你是怎么做到的?
  • 我在代码中添加了

标签: vue.js vue-router


【解决方案1】:

使用命名约定,以避免在路由结尾为 '/' 时也出现问题:

this.$router.push({name: pathForRouting})

路由器应该是这样的:

 path: 'something',
 name: 'pathForRouting',
 component: PublicIndex

【讨论】:

    猜你喜欢
    • 2019-10-28
    • 2021-06-03
    • 2018-02-15
    • 2021-11-06
    • 2017-03-06
    • 2021-10-16
    • 2017-12-18
    • 2019-07-24
    • 2019-05-28
    相关资源
    最近更新 更多