From bbb7a394148d11132960f643ae7e36739cca21b0 Mon Sep 17 00:00:00 2001 From: Dzmitry Shylovich Date: Fri, 2 Dec 2016 14:17:27 -0800 Subject: [PATCH] fix(router): allow specifying a matcher wihtout specifying a path fixes #12972 --- modules/@angular/router/src/config.ts | 7 ++++--- modules/@angular/router/test/config.spec.ts | 10 +++++++--- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/modules/@angular/router/src/config.ts b/modules/@angular/router/src/config.ts index f933a387a6..def2c22801 100644 --- a/modules/@angular/router/src/config.ts +++ b/modules/@angular/router/src/config.ts @@ -392,10 +392,11 @@ function validateNode(route: Route): void { throw new Error( `Invalid configuration of route '${route.path}': one of the following must be provided (component or redirectTo or children or loadChildren)`); } - if (route.path === undefined) { - throw new Error(`Invalid route configuration: routes must have path specified`); + if (route.path === void 0 && route.matcher === void 0) { + throw new Error( + `Invalid route configuration: routes must have either a path or a matcher specified`); } - if (route.path.startsWith('/')) { + if (typeof route.path === 'string' && route.path.charAt(0) === '/') { throw new Error( `Invalid route configuration of route '${route.path}': path cannot start with a slash`); } diff --git a/modules/@angular/router/test/config.spec.ts b/modules/@angular/router/test/config.spec.ts index 0d53b90439..20f8eb8eaf 100644 --- a/modules/@angular/router/test/config.spec.ts +++ b/modules/@angular/router/test/config.spec.ts @@ -16,6 +16,10 @@ describe('config', () => { () => validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}])) .not.toThrow(); }); + + it('should not throw when a matcher is provided', () => { + expect(() => validateConfig([{matcher: 'someFunc', component: ComponentA}])) + .not.toThrow(); }); it('should throw for undefined route', () => { @@ -67,9 +71,9 @@ describe('config', () => { }); it('should throw when path and matcher are missing', () => { - expect(() => { - validateConfig([{component: null, redirectTo: 'b'}]); - }).toThrowError(`Invalid route configuration: routes must have path specified`); + expect(() => { validateConfig([{component: null, redirectTo: 'b'}]); }) + .toThrowError( + `Invalid route configuration: routes must have either a path or a matcher specified`); }); it('should throw when none of component and children or direct are missing', () => {