我有两条路线:
{
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
是一个文字。除了重写路由以使它们在“签名”中不匹配之外,还有什么方法可以解决这个问题吗?
最佳答案
交换位置,将参数从一个变为下一个,一切都会正常
{
path: 'application/:groupId/applicant-detail/:applicant-id',
component: BarComponent
},
{
path: 'application/:groupId/:approved/:applicant-id',
component: FooComponent
}
关于javascript - 防止 Angular 2 路由器将文字误认为参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45866998/