【问题标题】:Angular 2 nested navigation with new router带有新路由器的 Angular 2 嵌套导航
【发布时间】:2016-05-13 20:15:40
【问题描述】:

如何实现嵌套导航?我以前的路由器就有这个。

{ path: '/admin/...', component: AdminLayoutComponent }

似乎来自 rc1 的 angular2 不支持这个。

来自文档。 https://angular.io/docs/ts/latest/guide/router.html

请注意,路径以斜杠和三个尾随句点 (/...) 结尾。

这意味着这是一条不完整的路线(非终端路线)。完成的路由将是父 /crisis-center/ 路由和来自子路由器的属于指定组件的路由的某种组合。

编辑: 这些是我的路线

//AppComponent
@Routes([
    { path: '/admin-login', component: AdminLoginLayoutComponent },
    { path: '/admin', component: AdminLayoutComponent },
    { path: '/edit', component: EditReportLayoutComponent },
    { path: '/', component: WebLayoutComponent },
])

//WebLayoutComponent
@Routes([
    { path: '/details/:id', component: DetailsComponent },
    { path: '/applications', component: ApplicationsComponent },
    { path: '/statistics', component: StatisticsComponent },
    { path: '/addreport', component: NewReportComponent },
    { path: '/register', component: RegisterComponent },
    { path: '/account', component: AccountComponent },
    { path: '/login', component: LoginComponent },
    { path: '/feed', component: AllFeedComponent },
    { path: '/', component: MapComponent }
])

编辑:在 plunker http://plnkr.co/edit/4TAd436l91zGX2emsxEF?p=preview 上添加了一个最小示例

【问题讨论】:

    标签: typescript angular


    【解决方案1】:

    如果您有子路由,只需删除新路由器中不需要的/...。新路由器仍然存在一些问题,并非所有功能都可用。一个(陷阱是路线的顺序是相关的(将按设计固定)。最具体(最长)的路线应该放在第一位,更通用的路线放在最后(如/,或@ 987654323@)

    【讨论】:

    • 所以这就是解决方案 { path: '/admin/', component: AdminLayoutComponent },
    • 我得到异常:错误:未捕获(承诺):无法匹配任何路线。当前部分:“统计”。可用路由:['/admin-login', '/admin', '/edit', '/']。不尊重任何子路线:)
    • 什么时候做什么?路由器链接?它看起来怎么样?
    • [routerLink]="['/statistics']" 例如
    • 这个 routerLink 在哪里?请尝试[routerLink]="['/','statistics']"
    猜你喜欢
    • 2016-09-09
    • 2016-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-01
    • 1970-01-01
    相关资源
    最近更新 更多