fix(router): allow specifying a matcher wihtout specifying a path

fixes #12972
This commit is contained in:
Dzmitry Shylovich 2016-12-02 14:17:27 -08:00 committed by Alex Rickabaugh
parent d7d8fab211
commit bbb7a39414
2 changed files with 11 additions and 6 deletions

View File

@ -392,10 +392,11 @@ function validateNode(route: Route): void {
throw new Error( throw new Error(
`Invalid configuration of route '${route.path}': one of the following must be provided (component or redirectTo or children or loadChildren)`); `Invalid configuration of route '${route.path}': one of the following must be provided (component or redirectTo or children or loadChildren)`);
} }
if (route.path === undefined) { if (route.path === void 0 && route.matcher === void 0) {
throw new Error(`Invalid route configuration: routes must have path specified`); 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( throw new Error(
`Invalid route configuration of route '${route.path}': path cannot start with a slash`); `Invalid route configuration of route '${route.path}': path cannot start with a slash`);
} }

View File

@ -16,6 +16,10 @@ describe('config', () => {
() => validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}])) () => validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}]))
.not.toThrow(); .not.toThrow();
}); });
it('should not throw when a matcher is provided', () => {
expect(() => validateConfig([{matcher: <any>'someFunc', component: ComponentA}]))
.not.toThrow();
}); });
it('should throw for undefined route', () => { it('should throw for undefined route', () => {
@ -67,9 +71,9 @@ describe('config', () => {
}); });
it('should throw when path and matcher are missing', () => { it('should throw when path and matcher are missing', () => {
expect(() => { expect(() => { validateConfig([{component: null, redirectTo: 'b'}]); })
validateConfig([{component: null, redirectTo: 'b'}]); .toThrowError(
}).toThrowError(`Invalid route configuration: routes must have path specified`); `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', () => { it('should throw when none of component and children or direct are missing', () => {