I'm using a resolver component but I cannot get the id from the url.
Stackblitz - https://stackblitz.com/edit/angular-x4djgz
In the stackblitz if I navigate to supplier/3
:
I get params.get('id') null
from the resolver and params.get('id') 3
from the end component. How do I get the endpoint id inside the resolver.
route.paramMap.subscribe(
(params: ParamMap) => {
console.log("params.get('id')", params.get('id'));
}
);
This question has been heavily edited as I thought originally this had something to do with being an angular+electron app.
Steps to get current route URL in Angular. Import Router,NavigationEnd from '@angular/router' and inject in the constructor. Subscribe to the NavigationEnd event of the router. Get the current route url by accessing NavigationEnd's url property.
According to the Angular doc, as you can see in example in the guide, the resolve
method takes two parameters that are relative to the actual route your are trying to resolve.
Using this in the resolver fixes the problem:
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot){
console.log("params.get('id')", route.paramMap.get('id'));
return of('dummy').pipe(delay(50));
}
https://stackblitz.com/edit/angular-4fkspm
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With