我的路线定义为:
path: 'geooperations',
component: GeoMetricsComponent,
children: [
{ path: ':idgeooperationmetrictype', component: DetailGeoMetricTypeComponent, outlet: 'geo' },
{ path: ':idgeooperationmetrictype/edit', component: DetailGeoMetricTypeComponent, outlet: 'geo' },
{ path: '/new', component: DetailGeoMetricTypeComponent, outlet: 'geo' }
]
示例: 网址:geooperations /(geo:c56da64c-0ef5-4894-83ee-043818b44e14)
outlet : 'geo'
idgeooperationmetrictype: 'c56da64c-0ef5-4894-83ee-043818b44e14'
我如何才能获得' idgeooperationmetrictype'来自ActivatedRoute?
答案 0 :(得分:1)
您需要在组件内订阅#34; DetailGeoMetricTypeComponent"
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['idgeooperationmetrictype'];
});
}
或者使用params行的dev工具设置断点以查看键。
答案 1 :(得分:0)
使用snapshot.params:
解决了这个问题this.activatedRoute.snapshot.params.subscribe(params => {
console.log(params['idgeooperationmetrictype']);
});