This is the archived documentation for Angular v5. Please visit angular.io to see documentation for the current version of Angular.

UrlMatcher

npm Package @angular/router
Module import { UrlMatcher } from '@angular/router';
Source router/src/config.ts

A function matching URLs

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

Description

A custom URL matcher can be provided when a combination of path and pathMatch isn't expressive enough.

For instance, the following matcher matches html files.

      
      export function htmlFiles(url: UrlSegment[]) {
  return url.length === 1 && url[0].path.endsWith('.html') ? ({consumed: url}) : null;
}

export const routes = [{ matcher: htmlFiles, component: AnyComponent }];