Angular 2: getting RouteParams from parent component

前端 未结 13 861
暖寄归人
暖寄归人 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:24

    In RC6, router 3.0.0-rc.2 (probably works in RC5 as well), you can take route params from the URL as a snapshot in case that params won't change, without observables with this one liner:

    this.route.snapshot.parent.params['username'];

    Don't forget to inject ActivatedRoute as follows:

    constructor(private route: ActivatedRoute) {};

    0 讨论(0)
提交回复
热议问题