【发布时间】:2017-03-22 13:58:11
【问题描述】:
我的子模块路线如下,
{
path: '',
children: [
{ path: '', component: TripManagerComponent },
{ path: ':id', component: TripDetailComponent },
{ path: 'new', component: TripNewComponent }
]
}
我正在如下导航到这些路线,
navigateToTrip(index: number) {
this.router.navigate([index], { relativeTo: this.route });
}
navigateToNewTrip() {
this.router.navigate(['new'], { relativeTo: this.route });
}
但是 Angular 将 new 路由检测为 :id 并将我导航到 TripDetailComponent。
这里的问题是 Angular 检测到“新”字符串作为 :id 路由的 url 参数。
我可以为:id 添加一个前缀,即view/:id 并使其工作。但是,我需要保持 url 模式不变。有没有办法做到这一点?
我预期的 url 模式是,
/trips --> show all trips
/trips/2334 --> show details of trip 2334
/trips/new --> show a form to create a new trip
【问题讨论】: