Struggling with passing routing parameters to my component when loaded in a subroute using Angular 2 rc.1 and TypeScript, and utilizing the @angular/router-deprecated
package.
In the routes configuration of my root component, I have set it up like this:
@RouteConfig([
{path:'/top', name:'Top', component: EndPointComponent},
{path:'/sub/...', name:'Sub', component: MiddleManComponent}
])
Below is the code for the endpoint component where parameter reading is attempted:
import {Component} from '@angular/core';
import {RouteParams} from '@angular/router-deprecated';
@Component({
template: 'Route Params: {{routeParams.params | json}}'
})
export class EndPointComponent{
constructor(private routeParams:RouteParams){}
}
And here's the code for the middleman component featuring the subroute to EndPointComponent:
import {Component} from '@angular/core';
import {RouteConfig, ROUTER_DIRECTIVES} from '@angular/router-deprecated';
import {EndPointComponent} from "./endpoint.component";
@Component({
directives: [ROUTER_DIRECTIVES]
template: `<router-outlet></router-outlet>`
})
@RouteConfig([
{path: '/end', name: 'End', component: EndPointComponent, useAsDefault: true}
])
export class MiddleManComponent {}
When loading the component from the top-level route (e.g., 'Top' in the root component), I can successfully read parameters from the routeParams
object of EndPointComponent
. However, the parameters are always empty when navigating to EndPointComponent
through MiddleManComponent
(e.g., via the 'Sub' route in the root component).
Do children routers override parent parameters before resolving routes? This seems illogical, so I must be overlooking something. How exactly can I pass route parameters to a subroute?
PS: Attempted to create a plunker for demonstration purposes, but had difficulties figuring out why the application wouldn't load. Link to the attempt: here