fix(router): allow specifying a matcher wihtout specifying a path
fixes #12972
This commit is contained in:
parent
d7d8fab211
commit
bbb7a39414
|
@ -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`);
|
||||
}
|
||||
|
|
|
@ -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', () => {
|
||||
|
@ -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', () => {
|
||||
|
|
Loading…
Reference in New Issue