From aa88438b5487aaac6afcaca2899f0bdbae657278 Mon Sep 17 00:00:00 2001 From: Hiroto Fukui Date: Fri, 15 Jul 2016 00:28:31 +0900 Subject: [PATCH] feat(Router): add extra validation for when route was passed as Array (#9942) --- modules/@angular/router/src/config.ts | 3 +++ modules/@angular/router/test/config.spec.ts | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/modules/@angular/router/src/config.ts b/modules/@angular/router/src/config.ts index 25f926fb8f..544bc95ff9 100644 --- a/modules/@angular/router/src/config.ts +++ b/modules/@angular/router/src/config.ts @@ -503,6 +503,9 @@ export function validateConfig(config: Routes): 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) { throw new Error( `Invalid configuration of route '${route.path}': redirectTo and children cannot be used together`); diff --git a/modules/@angular/router/test/config.spec.ts b/modules/@angular/router/test/config.spec.ts index 98213b3540..c85377a0f9 100644 --- a/modules/@angular/router/test/config.spec.ts +++ b/modules/@angular/router/test/config.spec.ts @@ -6,6 +6,15 @@ describe('config', () => { 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', () => { expect(() => { validateConfig(