Angular 6 第二嵌套子路线不起作用

标签 angular angular-router

我正在使用以下链接进行实验。 https://angular.io/guide/router#the-sample-application

正如您所看到的,制定路由有几个里程碑。 在遵循这些里程碑的过程中,我遇到了一些错误。 https://angular.io/guide/router#child-route-configuration 在这一步中,我无法继续,因为第二条路线不起作用。

const crisisCenterRoutes: Routes = [
  {
    path: 'crisis-center',
    component: CrisisCenterComponent,
    children: [
      {
        path: '',
        component: CrisisListComponent,
        children: [
          {
            path: ':id',
            component: CrisisDetailComponent
          },
          {
            path: '',
            component: CrisisCenterHomeComponent
          }
        ]
      }
    ]
  }
];

第二条路线目前无法使用。

https://github.com/Js-Guru321/angular-router-sample 这是我的代码。

请帮助我!

最佳答案

添加<router-outlet>crisis-list.html一切都会正常) 每层嵌套路由都需要自己的router-outlet父路由内的标记

<ul class="crises">
  <li *ngFor="let crisis of crises$ | async" [routerLink]="['/crisis-center', crisis.id]"
    [class.selected]="crisis.id === selectedId">
      <span class="badge">{{ crisis.id }}</span>{{ crisis.name }}
  </li>
</ul>
<router-outlet></router-outlet>

关于Angular 6 第二嵌套子路线不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54962099/

相关文章:

angular - 在 Angular 5 中,刷新当前路由会重定向到父路由

angular - Edge - 在 Angular iframe 上导航会将 history.state 设置为 null

带日期掩码的 Angular mat-datepicker

angular - 服务事件不会正确影响模板

导航后的 Angular 显示 snackbar

javascript - 在 Angular 12 中过滤 NavigationEnd 事件?

Angular 在 Guard 中获取匹配的 url 路径

angular - Angular 2 Routing中的重复查询参数

angular - 组件更改自身时如何避免表达式 "changed after checked"错误

javascript - Angular 表单提交获取为对象而不是值