我有以下代码:
constructor(private router: Router, private route: ActivatedRoute)
...
public onClickAndNavigate(){
this.router.navigate(['../'], {relativeTo: this.route});
}
我的路由器结构是:
{ path: '', redirectTo: 'Page1', pathMatch: 'full'},
{ path: 'login', component: LoginComponent},
{ path: 'Page1', children: [
{ path: '', redirectTo: 'Child1', pathMatch: 'full'},
{ path: 'Child1', component: Child1Component},
]},
{ path: 'Page2', children: [
{ path: 'SubPage2', children: [
{ path: 'Child2', children: [
{ path: '', redirectTo: 'SubChild2', pathMatch: 'full'},
{ path: 'SubChild2', component: SubChild2Component },
{ path: 'SiblingSubChild2', component: SiblingSubChild2Component },
]}
]}
]}
我处于SiblingSubChild2状态,当我按下按钮并调用onClickAndNavigate函数时,我希望进入Child2状态,但是我的代码进入Page1。
为什么? :(
编辑:该函数在服务中,因为它必须通用。