feat(Router): add extra validation for when route was passed as Array (#9942)
This commit is contained in:
parent
85be729c70
commit
aa88438b54
@ -503,6 +503,9 @@ export function validateConfig(config: Routes): void {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function validateNode(route: Route): void {
|
function validateNode(route: Route): void {
|
||||||
|
if (Array.isArray(route)) {
|
||||||
|
throw new Error(`Invalid route configuration: Array cannot be specified`);
|
||||||
|
}
|
||||||
if (!!route.redirectTo && !!route.children) {
|
if (!!route.redirectTo && !!route.children) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
`Invalid configuration of route '${route.path}': redirectTo and children cannot be used together`);
|
`Invalid configuration of route '${route.path}': redirectTo and children cannot be used together`);
|
||||||
|
@ -6,6 +6,15 @@ describe('config', () => {
|
|||||||
validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}]);
|
validateConfig([{path: 'a', redirectTo: 'b'}, {path: 'b', component: ComponentA}]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should throw when Array is passed', () => {
|
||||||
|
expect(() => {
|
||||||
|
validateConfig([
|
||||||
|
{path: 'a', component: ComponentA},
|
||||||
|
[{path: 'b', component: ComponentB}, {path: 'c', component: ComponentC}]
|
||||||
|
]);
|
||||||
|
}).toThrowError(`Invalid route configuration: Array cannot be specified`);
|
||||||
|
});
|
||||||
|
|
||||||
it('should throw when redirectTo and children are used together', () => {
|
it('should throw when redirectTo and children are used together', () => {
|
||||||
expect(() => {
|
expect(() => {
|
||||||
validateConfig(
|
validateConfig(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user