给出此路径树:
const routes: Routes = [
{
path: 'admin',
children: [
{ path: '', component: AdminComponent },
{
path: 'course',
children: [
{
path: 'manage/:_id',
children: [
{
path: '', component: CourseComponent,
},
{
path: 'unit/:unitId',
children: [{
path: '',
component: UnitComponent,
}]
}]
},
]
},
]
},
];
从admin/course/manage/1/unit/1
到父级manage /:id的导航在两种常规导航方式下均无法正常工作。
<a routerLink="../../">router link Back</a>
<button (click)="back()">Imperative Back</button>
protected back() {
this.router.navigate(['../../'], { relativeTo: this.route, fragment: 'coolFrag' });
}
这里是StackBlitz
答案 0 :(得分:1)
由于您位于路径''
的子路径unit/:unitId
上,所以我认为这是因为您的路径在路径中为空。
与父路径节点(而不是当前的空节点)相关,它将为您工作
this.router.navigate(['../../'], { relativeTo: this.route.parent, fragment: 'coolFrag' });