question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

CanMatch snapshot queryParams doesn't work

See original GitHub issue

Which @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:closed
  • Created a year ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
atscottcommented, Sep 19, 2022

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

0reactions
angular-automatic-lock-bot[bot]commented, Oct 24, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found