【问题标题】:Invalid configuration of route '': redirectTo and children cannot be used together路由''配置无效:redirectTo和children不能一起使用
【发布时间】:2021-07-02 02:39:23
【问题描述】:

我正在尝试从一个组件导航到另一个组件,但我遇到了这个问题:路由''的配置无效:redirectTo 和子级不能一起使用。 请问怎么解决?

路由文件:

    {
    path: '',
     redirectTo: 'offre-management', pathMatch: 'full',

children: [
  { path: 'offre-mngmnt-sites-list-all',
    component: OffreMngmntSitesListAllComponent }
]
  }

当我调用方法导航到 OffreMngmntSitesListAllComponent 组件时的html文件:

<span role="button" (click)="showAll()">
  show all
</span>

当我有方法调用 OffreMngmntSitesListAllComponent 组件时的 ts 文件:

 showAll(){
this.router.navigate(["offre-mngmnt-sites-list-all"])
   }

【问题讨论】:

    标签: javascript html angular typescript


    【解决方案1】:

    如果OffreMngmntSitesListAllComponent 真的是你的子组件,那么你的路由应该是这样的:

    const routes = {
     path: 'offre-management',
     component: ${your office management component},
     children: [
       {
        path: 'offre-mngmnt-sites-list-all',
        component: OffreMngmntSitesListAllComponent
       },
       {
        path: '', redirectTo: 'offre-management', pathMatch: 'full',
       }
      ]
     };
    

    你的导航会是这样的:

    this.router.navigate(["offre-management/offre-mngmnt-sites-list-all"])
    

    【讨论】:

      猜你喜欢
      • 2023-02-15
      • 1970-01-01
      • 2021-10-20
      • 2017-06-04
      • 2017-01-25
      • 2017-12-20
      • 1970-01-01
      • 2018-08-04
      • 1970-01-01
      相关资源
      最近更新 更多