【问题标题】:Angular 2 Child RoutesAngular 2 子路由
【发布时间】:2016-07-25 22:10:23
【问题描述】:

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

  • +dashboard
  • +document

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

那我该怎么办?

我是不是像这样在父路由下放一个文件夹

  • app\+document\+chapter

做这种事是不是比较好

  • app\+document
  • app\+chapter

除此之外,我对一般路线有点困惑。我的理解是有一条已弃用的路线和一条新路线。我想我正在使用新系统,因为它是使用 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 不起作用。

但我对这一切有点陌生,我希望让我的应用程序设计尽可能“传统”

【问题讨论】:

    标签: angular angular2-routing angular-cli


    【解决方案1】:

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

    请参阅https://angular.io/docs/ts/latest/guide/router.html#!#route-config 了解如何配置新路由器。

    【讨论】:

      猜你喜欢
      • 2016-09-20
      • 2017-08-10
      • 1970-01-01
      • 1970-01-01
      • 2016-12-19
      • 1970-01-01
      • 2017-12-23
      • 2017-03-04
      • 1970-01-01
      相关资源
      最近更新 更多