我似乎无法在子路线之间导航。
路由器概述:
{
"sort": {
"sorter": {
"order": "desc",
"mode": "max"
}
},
"query": {
"bool": {
"must": [
{
"term": {
"muteFeedUserIds": "56f4ca2f44fc8650411170b0"
}
},
{
"term": {
"approvalStatus": "approved"
}
},
{
"range": {
"sorter": {
"from": "2015-06-28",
"include_upper": false
}
}
}
],
"should": []
}
}
}
我在child1组件中尝试导航到新的/类型路由,如下所示:
path: 'parent', component: parentComponent,
children: [
{ path: '', redirectTo: 'child1', pathMatch: 'full' },
{ path: 'child1', component: child1Component },
{ path: 'child2', component: child2Component },
{ path: 'new/:type', component: child3Component },
{ path: '**', component: PageNotFoundComponent }
]
但我一直收到错误:无法匹配任何路线。网址细分:'新/资产'。
如果我手动插入网址,它可以正常工作。
非常感谢帮助,谢谢!
答案 0 :(得分:15)
您可以使用../
this._router.navigate(['../new', objType], { relativeTo: this._route });
答案 1 :(得分:7)
this.router.navigate(['../../new'], { relativeTo: this._route })
或
this.router.navigate(['/parent/new'])
或使用锚标记:
<a [routerLink]=" ['../../new'] ">
Go to new
</a>
或者:
<a [routerLink]=" ['/parent/new'] ">
Go to new
</a>
答案 2 :(得分:3)
当您使用relativeTo
然后尝试导航时,您应该放入 relative 路径,而不仅仅是父项视点中的整个路径。在你的例子中,它应该更像是:
this._router.navigate([ '../', objType ], { relativeTo: this._route });