避免 Angular 2 路由器将文字误认为参数

Keep Angular 2 Router from Mistaking Literals for Params

我有两条路线:

{
path: 'application/:groupId/:approved/:applicant-id',
component: FooComponent  
}, 
{
path: 'application/:groupId/applicant-detail/:applicant-id',
component: BarComponent  
},

不同之处在于第一个 :approved 是参数,第二个 applicant-detail 是文字。当然,路由器认为:

this.router.navigate(['./applicant-detail/' + this.someId, { relativeTo: this.route });

想去第一条路线,因为它没有意识到applicant-detail是一个文字。除了重写路由使它们在 'signature' 中不匹配外,还有什么办法可以解决这个问题?

交换位置,让参数一个接一个,一切正常

{
path: 'application/:groupId/applicant-detail/:applicant-id',
component: BarComponent  
},
{
path: 'application/:groupId/:approved/:applicant-id',
component: FooComponent  
}

路由器配置的顺序很重要。

交换你的声明,使最直接的路径在前。