title: Angular 2: getting RouteParams from parent component
body: <p>How do I get the RouteParams from a parent component?</p>
  
  <p><code>App.ts</code>:</p>
  
  <pre><code>@Component({
    ...
  })
  
  @RouteConfig([
    {path: '/', component: HomeComponent, as: 'Home'},
    {path: '/:username/...', component: ParentComponent, as: 'Parent'}
  ])
  
  export class HomeComponent {
    ...
  }
  </code></pre>
  
  <p>And then, in the <code>ParentComponent</code>, I can easily get my username param and set the child routes.</p>
  
  <p><code>Parent.ts</code>:</p>
  
  <pre><code>@Component({
    ...
  })
  
  @RouteConfig([
    { path: '/child-1', component: ChildOneComponent, as: 'ChildOne' },
    { path: '/child-2', component: ChildTwoComponent, as: 'ChildTwo' }
  ])
  
  export class ParentComponent {
  
    public username: string;
  
    constructor(
      public params: RouteParams
    ) {
      this.username = params.get('username');
    }
  
    ...
  }
  </code></pre>
  
  <p>But then, how can I get this same 'username' parameter in those child components? Doing the same trick as above, doesn't do it. Because those params are defined at the ProfileComponent or something??</p>
  
  <pre><code>@Component({
    ...
  })
  
  export class ChildOneComponent {
  
    public username: string;
  
    constructor(
      public params: RouteParams
    ) {
      this.username = params.get('username');
      // returns null
    }
  
    ...
  }
  </code></pre>