Skip to content

Commit

Permalink
fix(router): allow specifying a matcher wihtout specifying a path
Browse files Browse the repository at this point in the history
  • Loading branch information
vicb committed Dec 2, 2016
1 parent 202d9f8 commit f875cfb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
7 changes: 4 additions & 3 deletions modules/@angular/router/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
}
Expand Down
10 changes: 7 additions & 3 deletions modules/@angular/router/test/config.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: <any>'someFunc', component: ComponentA}]))
.not.toThrow();
});

it('should throw for undefined route', () => {
Expand Down Expand Up @@ -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', () => {
Expand Down

0 comments on commit f875cfb

Please sign in to comment.