I hope it will help someone else.
Question above states that query param value is needed after page has been redirected and we can assume that snapshot value (the no-observable alternative) would be sufficient.
No one here mentioned about snapshot.paramMap.get from the official documentation.
this.route.snapshot.paramMap.get('id')
So before sending it add this in sending/re-directing component:
import { Router } from '@angular/router';
then re-direct as either (documented here):
this.router.navigate(['/heroes', { id: heroId, foo: 'foo' }]);
or simply:
this.router.navigate(['/heroes', heroId ]);
Make sure you have added this in your routing module as documented here:
{ path: 'hero/:id', component: HeroDetailComponent }
And finally, in your component which needs to use the query param
add imports (documented here):
import { Router, ActivatedRoute, ParamMap } from '@angular/router';
inject ActivatedRoute
( documentation also imports switchMap and also injects Router and HeroService - but they are needed for observable alternative only - they are NOT needed when you use snapshot alternative as in our case ):
constructor(
private route: ActivatedRoute
) {}
NOTE: IF YOU ADD ROUTING-MODULE TO A FEATURE MODULE (AS SHOWN IN DOCUMENTATION) MAKE SURE THAT IN APP.MODULE.ts THAT ROUTING MODULE COMES BEFORE AppRoutingModule (or other file with root-level app routes) IN IMPORTS: [] . OTHERWISE FEATURE ROUTES WILL NOT BE FOUND (AS THEY WOULD COME AFTER { path: '**', redirectTo: '/not-found' } and you would see only not-found message).
@RouteConfig
for thispath
? – Pankaj Parkar