导航到子路线会给我:“错误:无法匹配任何路线”(角度6)

时间:2018-08-06 10:37:12

标签: angular angular-routing

第一个示例有效(但写得不好)。

const FooProcessingRoutes: Routes = [{
  path: '',
  pathMatch: 'full',
  redirectTo: '/foo-processing/list',
}, {
  path: 'list',
  component: FooListComponent,
}, {
  path: 'another-list',
  component: FooAnotherListComponent,
}, {
  path: 'another-list/:id/details',
  component: FooAnotherListComponent,
  children: [{
    path: '',
    component: FooAnotherListDetailsComponent,
    outlet: 'details-view',
  }]
}];

export { FooProcessingRoutes };

第二个示例应该起作用(我认为),我想这样做:

const FooProcessingRoutes: Routes = [{
  path: '',
  pathMatch: 'full',
  redirectTo: '/foo-processing/list',
}, {
  path: 'list',
  component: FooListComponent,
}, {
  path: 'another-list',
  component: FooAnotherListComponent,
  children: [{
    path: ':id/details',
    outlet: 'details-view',
    component: FooAnotherListDetailsComponent,
  }],
}];

export { FooProcessingRoutes };

我需要:id/details成为another-list的子代。这两个示例都链接到我的浏览器中的相同路径(即http://localhost:4200/#/foo-processing/another-list/1/details)。

但是,第二个示例在Chrome / Firefox中给了我Error: Cannot match any routes. URL Segment: 'foo-processing/another-list/1/details'

我在那儿丢失了东西吗?还是那个错误?

1 个答案:

答案 0 :(得分:0)

应该是:

{
  path: 'another-list',
  component: FooAnotherListComponent,
  children: [{
    path: ':id/details',
    component: FooAnotherListDetailsComponent,
    outlet: 'details-view',
  }