From 3c3e9ddb107e259612b2e858f10fd11eaa4b0453 Mon Sep 17 00:00:00 2001 From: vsavkin Date: Fri, 29 Jul 2016 09:59:50 -0700 Subject: [PATCH] feat(router): add a validation to make sure pathMatch is set correctly --- modules/@angular/router/src/config.ts | 4 ++++ modules/@angular/router/test/config.spec.ts | 6 ++++++ 2 files changed, 10 insertions(+) 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'/); + }); }); });