diff --git a/modules/@angular/router/src/config.ts b/modules/@angular/router/src/config.ts index 111dc10bb5..e9df86e312 100644 --- a/modules/@angular/router/src/config.ts +++ b/modules/@angular/router/src/config.ts @@ -542,4 +542,8 @@ function validateNode(route: Route): void { throw new Error( `Invalid route configuration of route '{path: "${route.path}", redirectTo: "${route.redirectTo}"}': please provide 'pathMatch'. ${exp}`); } + if (route.pathMatch !== undefined && route.pathMatch !== 'full' && route.pathMatch !== 'prefix') { + throw new Error( + `Invalid configuration of route '${route.path}': pathMatch can only be set to 'prefix' or 'full'`); + } } diff --git a/modules/@angular/router/test/config.spec.ts b/modules/@angular/router/test/config.spec.ts index f8536f9160..9791164412 100644 --- a/modules/@angular/router/test/config.spec.ts +++ b/modules/@angular/router/test/config.spec.ts @@ -74,6 +74,12 @@ describe('config', () => { validateConfig([{path: '', redirectTo: 'b'}]); }).toThrowError(/Invalid route configuration of route '{path: "", redirectTo: "b"}'/); }); + + it('should throw when pathPatch is invalid', () => { + expect(() => { validateConfig([{path: 'a', pathMatch: 'invalid', component: 'b'}]); }) + .toThrowError( + /Invalid configuration of route 'a': pathMatch can only be set to 'prefix' or 'full'/); + }); }); });