|
85 | 85 | * @preferred @module ng2
|
86 | 86 | */
|
87 | 87 | /** */
|
88 |
| -import { Injector, Provider, PLATFORM_ID } from "@angular/core"; |
| 88 | +import { Injector, Provider, PLATFORM_ID, APP_INITIALIZER } from "@angular/core"; |
89 | 89 | import { isPlatformBrowser } from "@angular/common";
|
90 | 90 | import {
|
91 | 91 | UIRouter, PathNode, StateRegistry, StateService, TransitionService, UrlMatcherFactory, UrlRouter, ViewService,
|
@@ -154,20 +154,25 @@ export function uiRouterFactory(locationStrategy: LocationStrategy, rootModules:
|
154 | 154 | rootModules.forEach(moduleConfig => applyRootModuleConfig(router, injector, moduleConfig));
|
155 | 155 | modules.forEach(moduleConfig => applyModuleConfig(router, injector, moduleConfig));
|
156 | 156 |
|
157 |
| - // Start monitoring the URL |
158 |
| - if (!router.urlRouter.interceptDeferred) { |
159 |
| - router.urlService.listen(); |
160 |
| - router.urlService.sync(); |
161 |
| - } |
162 |
| - |
163 | 157 | return router;
|
164 | 158 | }
|
165 | 159 |
|
| 160 | +// Start monitoring the URL when the app starts |
| 161 | +export function appInitializer(router: UIRouter) { |
| 162 | + return () => { |
| 163 | + if (!router.urlRouter.interceptDeferred) { |
| 164 | + router.urlService.listen(); |
| 165 | + router.urlService.sync(); |
| 166 | + } |
| 167 | + } |
| 168 | +} |
| 169 | + |
166 | 170 | export function parentUIViewInjectFactory(r: StateRegistry) { return { fqn: null, context: r.root() } as ParentUIViewInject; }
|
167 | 171 |
|
168 | 172 | export const _UIROUTER_INSTANCE_PROVIDERS: Provider[] = [
|
169 | 173 | { provide: UIRouter, useFactory: uiRouterFactory, deps: [LocationStrategy, UIROUTER_ROOT_MODULE, UIROUTER_MODULE_TOKEN, Injector] },
|
170 | 174 | { provide: UIView.PARENT_INJECT, useFactory: parentUIViewInjectFactory, deps: [StateRegistry]},
|
| 175 | + { provide: APP_INITIALIZER, useFactory: appInitializer, deps: [UIRouter], multi: true }, |
171 | 176 | ];
|
172 | 177 |
|
173 | 178 | export function fnStateService(r: UIRouter) { return r.stateService; }
|
|
0 commit comments