Angular 2 条子路由

Angular 2 Child Routes

我使用了 angular-cli 工具来创建我的路线。它会创建一个前面带有 + 的文件夹,即

我不知道如何使用 angular-cli 工具创建子路由。这真的无关紧要,但我更愿意在我的应用程序结构中采用约定的约定来描述子路由。

那我该怎么办?

像这样在父路由下放一个文件夹吗

做这种事是不是比较好

除此之外,我对一般路线有点困惑。我的理解是有一条已弃用的路线和一条新路线。我想我正在使用新系统,因为它是使用 angular-cli 工具生成的。无论如何,我嵌套了多个级别的子路由。我想知道这看起来是否合法。

@Routes([
  { path: '/', component: DashboardComponent },
  { path: '/document/:id', component: ReaderComponent,
      children: [
          { path: '', redirectTo: 'chapter/0', pathMatch: 'full' },
          { path: 'chapter/:id', component: ChapterComponent,
            children: [
              { path: '', redirectTo: 'para/0', pathMatch: 'full' },
              { path: 'para/:id', component: ParagraphComponent }
           ]}
      ]
  }
])

所以 http://my-url/document/1 应该带我去 http://my-url/document/1/chapter/0/para/0 这是最好的方法吗?我喜欢它,因为它允许深度链接等。它也显示 redirectTo 不起作用。

但是我对这一切有点陌生,我想尽可能保持我的应用程序设计 'conventional'

您似乎混合了来自不同不兼容路由器版本的内容。 @Routes() 来自较旧的路由器版本,但您的路由配置适用于最新的路由器版本。

有关如何配置新路由器的信息,请参阅https://angular.io/docs/ts/latest/guide/router.html#!#route-config