angular2无法相对于父路线导航

Ker*_* Hu 5 angular2-routing angular-cli angular

我使用angular2 cli。

测试导航相对遇到的问题:

路由配置:

{
    path: '',
    component: CheckCompanyComponent,
    children:[
      {
        path:'',
        loadChildren: 'app/components/company/check-company-home/check-company-home.module#CheckCompanyHomeModule'
      },
      {
        path:':id',
        loadChildren: 'app/components/company/check-company-detail/check-company-detail.module#CheckCompanyDetailModule'
      }
    ]
  }
Run Code Online (Sandbox Code Playgroud)

在check-company-home组件中

goIdPage(){
    this.router.navigate(['22'], { relativeTo: this.route });
  }
Run Code Online (Sandbox Code Playgroud)

可以从“ / company”导航到“ / company / 22”

在check-company-detail组件中:

goBack(){
    this.router.navigate(['../'], { relativeTo: this.route });
  }
Run Code Online (Sandbox Code Playgroud)

但是无法将表格“ / company / 22”导航到“ / company”,

为什么?

Ric*_*nte 8

relativeTo: this.route.parent当我设置和使用 single dot时它起作用['./']

goBack(){
    this.router.navigate(['./'], { relativeTo: this.route.parent });
}
Run Code Online (Sandbox Code Playgroud)


Phi*_*ief 2

尝试只用一个点:

goBack(){
    this.router.navigate(['./'], { relativeTo: this.route });
}
Run Code Online (Sandbox Code Playgroud)