子路径路径可以在Angular 9路由的辅助/辅助路径中工作吗?

时间:2020-09-27 20:07:45

标签: angular angular9 angular-router

我在将子路由路径与Angular 9的辅助/辅助/命名路由器出口结合使用时遇到问题。

我确实在stackblitz中设置了一个示例: https://stackblitz.com/edit/angular9-routing-aux?file=src/app/app-routing.module.ts

为简单起见,以下正常/主要路线有效:

// For Primary outlet child routes work fine
{
  path: 'phome1',
  children: [
    {
      path: '',
      pathMatch: 'full', 
      component: PrimaryHome1Component
    },
    {
      path: 'pitem1',
      component: PItem1Component
    }
  ]
},

但是,如果我尝试对辅助/辅助路由使用相同的设置,则无法使用:

// For Auxiliary / Secondary outlet child routes don't seem to work
{
  path: 'cases',
  outlet: 'aux',
  children: [{
    path: '',
    pathMatch: 'full',
    component: CasesComponent,
    outlet: 'aux'
  },{
    path: ':id',
    component: EditCaseComponent,
    outlet: 'aux'
  }]
},

我得到的错误是路线不匹配或什么都没发生。

我做错什么了吗?

在此先感谢您的帮助!

1 个答案:

答案 0 :(得分:1)

问题在于应用程序路由文件中的命名。声明在顶层使用命名插座的路线后,您就无需继续指定它了:

{
  path: 'cases',
  outlet: 'aux',
  children: [{
    path: '',
    pathMatch: 'full',
    component: CasesComponent,
    // outlet: 'aux'   // remove this<<<<
  },{
    path: ':id',
    component: EditCaseComponent,
  }]
},