我的孩子模塊路線如下網址參數衝突,角2路線與其他路線
{
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 });
}
但角檢測new
路線作爲:id
並導航到TripDetailComponent
。
這裏的問題是Angular爲:id
路由檢測到'new'字符串作爲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
感謝Günter。有用。從來沒有想過訂單會很重要。 –
路線順序總是讓我:|感謝澄清這一點。 – moeabdol