我的router.navigate不从孩子导航到父母

时间:2018-07-16 09:49:29

标签: angular angular-ui-router

我有以下代码:

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。

为什么? :(

编辑:该函数在服务中,因为它必须通用。

0 个答案:

没有答案
相关问题