使用angular 8.x
;
tldr;
以下内容:
this.router.navigate(['../details'], { relativeTo: this.route });
导致:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'details'
绝对导航正常工作:
this.router.navigate(['/search/details']);
长版本...
请考虑以下功能模块的布线:
const searchRoutes: Routes = [
{
path: 'search',
component: SearchComponent,
children: [
{
path: '',
component: PersonSearchComponent,
children: [
{
path: 'details',
component: DetailsComponent
},
{
path: '',
component: QueryComponent
}
]
}
]
}
];
app-routing.module:
const routes: Routes = [
{path: '', redirectTo: '/search', pathMatch: 'full'},
];
localhost:4200/
正确地重定向到localhost:4200/search
。显示QueryComponent
的模板。
使用相对导航如何从'details'
内部导航到QueryComponent
路线? (同级导航)
根据angular docs,此方法应该有效:
this.router.navigate(['../details'], { relativeTo: this.route });