Skip to content

[Router] Add defaultUrlMatcher to public API #35928

@RoboBurned

Description

@RoboBurned

🚀 feature request

Relevant Package

This feature request is for @angular/router

Description

There should be ability to access defaultUrlMatcher from user's code.
Ability to access and use it in custom implementations of UrlMatcher will ease developing of custom url matchers like in this question:
https://stackoverflow.com/a/41543827/5358442

function digitsMatcher(segments: UrlSegment[], segmentGroup: UrlSegmentGroup, route: Route): UrlMatchResult | null {
  const result = defaultUrlMatcher(segments, segmentGroup, route);

  if (!result || !result.consumed || result.consumed.length < 1) {
    return;
  }

  const re = /^\d+$/;
  const match = re.exec(result.consumed[0].path);

  if (match) {
    return result;
  }

  return null;
}

Describe the solution you'd like

There should be ability to import default URL matcher and call it from user-defined custom matcher.

Describe alternatives you've considered

Another solution of "my" case can be adding support of constraints for route params with few built-in constraints like Integer and Regex and ability to create custom constraints.
This could look something like this:

const routes: Routes = [
 { path: ':clientId/:lang', component: ClientOpenComponent,
    constraints: { 
               clientId: [RouteParamConstraints.Integer], /*built-in*/
               lang: [LangRouterParamConstraint] } /*custom*/
}];

Metadata

Metadata

Assignees

Labels

area: routerfeatureLabel used to distinguish feature request from other issuesfreq1: low

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions