如何从 ActivatedRoute (Angular2) 获取出口参数

How to get outlet params from ActivatedRoute (Angular2)

我的路线定义为:

    path: 'geooperations',
    component: GeoMetricsComponent,
    children: [
      { path: ':idgeooperationmetrictype', component: DetailGeoMetricTypeComponent, outlet: 'geo' },
      { path: ':idgeooperationmetrictype/edit', component: DetailGeoMetricTypeComponent, outlet: 'geo' },
      { path: '/new', component: DetailGeoMetricTypeComponent, outlet: 'geo' }
    ]

示例: URL: geoperations/(geo:c56da64c-0ef5-4894-83ee-04381​​8b44e14)

outlet : 'geo'
idgeooperationmetrictype: 'c56da64c-0ef5-4894-83ee-043818b44e14'

如何从 ActivatedRoute 获取 'idgeooperationmetrictype'?

您需要在组件内订阅它"DetailGeoMetricTypeComponent"

ngOnInit() {
    this.sub = this.route.params.subscribe(params => {
       this.id = params['idgeooperationmetrictype'];
    });
  }

或者使用开发工具在 params 行设置断点以查看密钥。

使用 snapshot.params 解决了问题:

this.activatedRoute.snapshot.params.subscribe(params => {           
   console.log(params['idgeooperationmetrictype']);
});