Hi I am trying to extract the id part of the url using Angular2.
http://localhost:3000/item/187809
I have been playing around with ActiveRoute within onInit but without luck
this.route.queryParams.forEach((params: any) => {
console.log("QUERYPARAMS");
console.log(params);
});
Also tried subscribing to route change like this
this.routeSub = this.route.queryParams.subscribe(params => {
console.log(params);
console.log(+params['id']);
});
but params is just an empty object.
I am defining the route as a lazy route like this
{
path: item',
children: [
{ path: ':id', loadChildren: './item/item.module#ItemModule' },
]
},
I think the problem is that I have a header component and a main component which holds the lazy loaded routed child. I am trying to load the id inside the header component.
Any idea what's missing?