Skip to content

Include URL parameters in canMatch interface #49309

@joelghill

Description

@joelghill

Which @angular/* package(s) are relevant/related to the feature request?

router

Description

The canMatch router guard accepts route: Route and segments: 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/:userId and when the browser navigates to the URL users/user_123 we should have access to a mapping of parameters similar to:

{
    "userId": "user_123",
}

I can't find this information anywhere at the time the canMatch guard 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 canMatch parameter or in the UrlSegment or the Route (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 canActivate method has access to this data via the activated route snapshot (params object) and I don't understand why we can't have something similar in canMatch?

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: routerfeatureLabel used to distinguish feature request from other issues

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions