如何获取路由器中声明的嵌套路由列表?

How to get a list of nested routes declared in the router?

我的 Angular 2 应用程序中有一个仪表板路线,它的子路线很少。

{ path: 'app/:property', component: DashboardComponent, canActivate: [AuthGuardService], 
  children: [
    { path: 'home', component: HomeComponent }
    { path: 'welcome-slide', component: WelcomeSlideComponent }
    { path: 'analytics', component: AnalyticsComponent }
  ]
},

有没有办法让我获得子路由列表及其路径(也许还有名称),然后我可以使用它们来填充我的导航栏?

this.router.config

虽然路线没有名称,但其他信息可用。

另见 https://angular.io/docs/ts/latest/api/router/index/Routes-type-alias.html

使用 router.routerState 您还可以迭代父路由器和子路由器以从中获取路由。