【问题标题】:angular2 can't navigating relative to parent routeangular2 无法相对于父路线导航
【发布时间】:2016-11-03 07:44:22
【问题描述】:

我使用 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'
      }
    ]
  }

在 check-company-home 组件中

goIdPage(){
    this.router.navigate(['22'], { relativeTo: this.route });
  }

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

在 check-company-detail 组件中:

goBack(){
    this.router.navigate(['../'], { relativeTo: this.route });
  }

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

为什么?

【问题讨论】:

    标签: angular angular2-routing angular-cli


    【解决方案1】:

    当我设置 relativeTo: this.route.parent 并使用单点 ['./'] 时,它可以工作。

    goBack(){
        this.router.navigate(['./'], { relativeTo: this.route.parent });
    }
    

    【讨论】:

      【解决方案2】:

      只用一个点试试:

      goBack(){
          this.router.navigate(['./'], { relativeTo: this.route });
      }
      

      【讨论】:

      猜你喜欢
      • 2017-01-08
      • 2016-10-29
      • 2017-04-21
      • 1970-01-01
      • 2017-10-15
      • 2018-06-08
      • 2018-03-30
      • 1970-01-01
      • 2016-11-14
      相关资源
      最近更新 更多