diff --git a/packages/router/src/utils/config.ts b/packages/router/src/utils/config.ts index f8f53c6cc6..ed45e9b151 100644 --- a/packages/router/src/utils/config.ts +++ b/packages/router/src/utils/config.ts @@ -58,6 +58,12 @@ function validateNode(route: Route, fullPath: string): void { throw new Error(`Invalid configuration of route '${ fullPath}': redirectTo and component cannot be used together`); } + if (route.redirectTo && route.canActivate) { + throw new Error( + `Invalid configuration of route '${ + fullPath}': redirectTo and canActivate cannot be used together. Redirects happen before activation ` + + `so canActivate will never be executed.`); + } if (route.path && route.matcher) { throw new Error( `Invalid configuration of route '${fullPath}': path and matcher cannot be used together`); diff --git a/packages/router/test/config.spec.ts b/packages/router/test/config.spec.ts index 76d32f3f5a..248767d415 100644 --- a/packages/router/test/config.spec.ts +++ b/packages/router/test/config.spec.ts @@ -98,6 +98,15 @@ describe('config', () => { `Invalid configuration of route 'a': redirectTo and component cannot be used together`); }); + it('should throw when component and redirectTo are used together', () => { + expect(() => { + validateConfig([{path: 'a', redirectTo: 'b', canActivate: []}]); + }) + .toThrowError( + `Invalid configuration of route 'a': redirectTo and canActivate cannot be used together. ` + + `Redirects happen before activation so canActivate will never be executed.`); + }); + it('should throw when path and matcher are used together', () => { expect(() => { validateConfig([{path: 'a', matcher: 'someFunc', children: []}]);