CanMatch snapshot queryParams doesn't work
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
router
Is this a regression?
No
Description
I want a sync access to router.snapshot.queryParams
in CanMatch
guard and it doesn’t work:
{
path: 'todos',
canMatch: [() => {
// the location is todos?foo=1
console.log(inject(ActivatedRoute).snapshot.queryParams) // { }
return true;
}],
}
If I wrap it with a setTimeout
it logs the correct value.
Please provide a link to a minimal reproduction of the bug
No response
Please provide the exception or error you saw
No response
Please provide the environment you discovered this bug in (run ng version
)
No response
Anything else?
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
Angular: queryParams does not work when updating url ...
The value isn't updating, because the snapshot of the route is taken at the first load of the component. The value will only...
Read more >Create UrlTree from Any ActivatedRouteSnapshot in Angular
If this doesn't work, the UrlTree creation fails. ... function takes an ActivatedRouteSnapshot , commands , and optional queryParams and fragments and ...
Read more >Router tutorial: tour of heroes - Angular
In this tutorial, you build upon a basic router configuration to explore features such as child routes, route parameters, lazy load NgModules, guard...
Read more >Accessing Parent And Child Route Segment Parameters In ...
// changes so that we don't continually load data in the background. // --. // CAUTION: The Angular documentation indicates that you don't...
Read more >Getting Query Params from Angular's Router - Ultimate Courses
Accessing the Query Params snapshot ... This is a nice and simple way to access your query params with Angular's router, however it...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The current activated route is the current activated route. This is as @JoostK has described. Closing as working as intended.
FYI - you can get what you’re looking for with
inject(Router).getCurrentNavigation().initialUrl.queryParams
https://stackblitz.com/edit/angular-ivy-sgtr4a?file=src%2Fmain.ts,src%2Findex.html
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.