Angular 2: getting RouteParams from parent component

前端 未结 13 964
暖寄归人
暖寄归人 2020-11-28 04:47

How do I get the RouteParams from a parent component?

App.ts:

@Component({
  ...
})

@RouteConfig([
  {path: \'/\', component: HomeCompo         


        
13条回答
  •  悲&欢浪女
    2020-11-28 05:18

    RC5 + @angular/router": "3.0.0-rc.1 SOLUTION: It seems that this.router.routerState.queryParams has been deprecated. You can get the parent route params this way:

    constructor(private activatedRoute: ActivatedRoute) {
    }    
    
    this.activatedRoute.parent.params.subscribe(
      (param: any) => {
        let userId = param['userId'];
        console.log(userId);
      });
    

提交回复
热议问题