New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Include URL parameters in canMatch interface #49309
Comments
This is because It is possible that we could investigate accumulating a set of currently matched parameters up to the point of hitting the Note that the lack of having this information is effectively what's blocking this feature request because the experience would be sub-optimal: #13373 |
Thanks for responding! I think this is the part I'm confused about. What in the route config can affect parameters at the point in time of executing For my use case I really need something dead simple to cover most cases:
Unless I'm missing something I could probably write a custom guard that does the parsing I need, I'm just surprised it's not there already and I'm unaware of what in the overall architecture would prevent this. Again, I don't have a deep understanding of what angular is doing under the hood though. |
|
I should also add that perhaps |
We absolutely have an easy way to access the params of the current route being matched. However these are not final because a redirect may cause parameters and parameter names to change. You can get this information manually by just rerunning the matcher on those segments in your guard: https://stackblitz.com/edit/angular-6m5gvr?file=src%2Fmain.ts These are just the current route though and again as I mentioned above, we don't currently pass down the parameter matches from the parent configs (you also would definitely not have access to any child parameters no mater what). Also, because we haven't matched all the parent's children, we can't construct the parent tree object (
I think part of the confusion is that the Long story short, I do think this is a problem that we should fix, especially if we want to land #13373 (and we do). I would guess that nobody really thought about this before. |
|
This feature request is now candidate for our backlog! In the next phase, the community has 60 days to upvote. If the request receives more than 20 upvotes, we'll move it to our consideration list. You can find more details about the feature request process in our documentation. |
|
Thank you @atscott, your response and sample code was super helpful! I was eventually able to get done what I needed to with the |
|
Just a heads up that we kicked off a community voting process for your feature request. There are 20 days until the voting process ends. Find more details about Angular's feature request process in our documentation. |

Formed in 2009, the Archive Team (not to be confused with the archive.org Archive-It Team) is a rogue archivist collective dedicated to saving copies of rapidly dying or deleted websites for the sake of history and digital heritage. The group is 100% composed of volunteers and interested parties, and has expanded into a large amount of related projects for saving online and digital history.

Which @angular/* package(s) are relevant/related to the feature request?
router
Description
The
canMatchrouter guard acceptsroute: Routeandsegments: UrlSegment[]as arguments. Neither of these objects contain the parameters that may or may not be in the URL.Example
A URL path will be set to
users/:userIdand when the browser navigates to the URLusers/user_123we should have access to a mapping of parameters similar to:I can't find this information anywhere at the time the
canMatchguard is activated. Parameters objects in the URL segments are empty, and the Route object does not have a params object, and using the activate route service also does not provide a solution. Am I doing something wrong?Proposed solution
Provide an object, either as a
canMatchparameter or in theUrlSegmentor theRoute(I don't really care where they are, whatever makes sense to the Angular routing design) that includes the URL parameters.Alternatives considered
We can currently take the path in the route, and the URL segments, compare them, and derive the parameters from there.
I feels like shouldn't have to do this though? The
canActivatemethod has access to this data via the activated route snapshot (params object) and I don't understand why we can't have something similar incanMatch?The text was updated successfully, but these errors were encountered: