From 131914ac94cd8858446bd4e083be061b5d13f5de Mon Sep 17 00:00:00 2001 From: vsavkin Date: Wed, 8 Jun 2016 19:00:47 -0700 Subject: [PATCH] fix(router): fix lazy loading issues --- .../@angular/router/src/common_router_providers.ts | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/@angular/router/src/common_router_providers.ts b/modules/@angular/router/src/common_router_providers.ts index 70abba7915..a01c99f12c 100644 --- a/modules/@angular/router/src/common_router_providers.ts +++ b/modules/@angular/router/src/common_router_providers.ts @@ -55,8 +55,14 @@ export function provideRouter(config: RouterConfig): any[] { { provide: APP_INITIALIZER, multi: true, - useFactory: (router: Router) => router.initialNavigation(), - deps: [Router] - }, + useFactory: (injector) => { + // https://github.com/angular/angular/issues/9101 + // Delay the router instantiation to avoid circular dependency (ApplicationRef -> + // APP_INITIALIZER -> Router) + setTimeout(_ => injector.get(Router).initialNavigation(), 0); + return _ => null; + }, + deps: [Injector] + } ]; }