{ "id": "api/router/UrlMatcher", "title": "UrlMatcher", "contents": "\n\n
\n
\n
\n \n API > @angular/router\n
\n \n
\n \n
\n

UrlMatcherlink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

A function for matching a route against URLs. Implement a custom URL matcher\nfor Route.matcher when a combination of path and pathMatch\nis not expressive enough. Cannot be used together with path and pathMatch.

\n\n

See more...

\n
\n \n \n \n
\n \n type UrlMatcher = (segments: UrlSegment[], group: UrlSegmentGroup, route: Route) => UrlMatchResult | null;\n \n
\n\n \n\n \n \n
\n

Descriptionlink

\n

The function takes the following arguments and returns a UrlMatchResult object.

\n
    \n
  • segments : An array of URL segments.
  • \n
  • group : A segment group.
  • \n
  • route : The route to match against.
  • \n
\n

The following example implementation matches HTML files.

\n\nexport function htmlFiles(url: UrlSegment[]) {\n return url.length === 1 && url[0].path.endsWith('.html') ? ({consumed: url}) : null;\n}\n\nexport const routes = [{ matcher: htmlFiles, component: AnyComponent }];\n\n\n \n
\n\n\n \n\n\n
\n
\n\n\n" }