我似乎不能在子路由之间导航。
路由器概述:
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 }
]我在child1组件中尝试导航到新的/类型路由,如下所示:
this._router.navigate(['new', objType], { relativeTo: this._route });但我一直收到错误:无法匹配任何路由。URL段:‘new/’。
如果我手动插入url,它就能正常工作。
非常感谢您的帮助,谢谢!
发布于 2016-12-30 20:52:04
您可以使用../
this._router.navigate(['../new', objType], { relativeTo: this._route });发布于 2016-12-30 21:13:21
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>发布于 2016-12-30 20:52:10
当您使用relativeTo然后尝试导航时,您应该放入相对路径,而不仅仅是从parents的角度来看整个路径。在您的示例中,它应该更类似于:
this._router.navigate([ '../', objType ], { relativeTo: this._route });https://stackoverflow.com/questions/41396519
复制相似问题