Skip to content

Commit c688f5b

Browse files
aitboudadchristopherthielen
authored andcommitted
[ssr][lazyload] prevent page flicker
1 parent eadb582 commit c688f5b

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/uiRouterNgModule.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
/** */
33
import { Ng2StateDeclaration } from "./interface";
44
import {
5-
NgModule, ModuleWithProviders, ANALYZE_FOR_ENTRY_COMPONENTS, Provider, Injector, InjectionToken
5+
NgModule, ModuleWithProviders, ANALYZE_FOR_ENTRY_COMPONENTS, Provider, Injector, InjectionToken, APP_INITIALIZER, PLATFORM_ID,
66
} from "@angular/core";
7-
import { CommonModule, LocationStrategy, HashLocationStrategy, PathLocationStrategy } from "@angular/common";
7+
import { CommonModule, LocationStrategy, HashLocationStrategy, PathLocationStrategy, isPlatformServer } from "@angular/common";
88
import { _UIROUTER_DIRECTIVES } from "./directives/directives";
99
import { UIView } from "./directives/uiView";
10-
import { UrlRuleHandlerFn, TargetState, TargetStateDef, UIRouter } from "@uirouter/core";
10+
import { UrlRuleHandlerFn, TargetState, TargetStateDef, UIRouter, TransitionService } from "@uirouter/core";
1111
import { _UIROUTER_INSTANCE_PROVIDERS, _UIROUTER_SERVICE_PROVIDERS } from "./providers";
1212

1313
import { ROUTES } from "@angular/router";
@@ -16,12 +16,24 @@ import { ROUTES } from "@angular/router";
1616
/** @hidden */ export const UIROUTER_STATES = new InjectionToken("UIRouter States");
1717
// /** @hidden */ export const ROUTES = UIROUTER_STATES;
1818

19+
export function onTransitionReady(transitionService: TransitionService, plateformId) {
20+
if (isPlatformServer(plateformId)) {
21+
return () => Promise.resolve();
22+
}
23+
24+
return () => new Promise(resolve => {
25+
transitionService.onSuccess({}, resolve);
26+
transitionService.onError({}, resolve);
27+
});
28+
}
29+
1930
export function makeRootProviders(module: StatesModule): Provider[] {
2031
return [
2132
{ provide: UIROUTER_ROOT_MODULE, useValue: module, multi: true},
2233
{ provide: UIROUTER_MODULE_TOKEN, useValue: module, multi: true },
2334
{ provide: ROUTES, useValue: module.states || [], multi: true },
2435
{ provide: ANALYZE_FOR_ENTRY_COMPONENTS, useValue: module.states || [], multi: true },
36+
{ provide: APP_INITIALIZER, useFactory: onTransitionReady, deps: [TransitionService, PLATFORM_ID], multi: true },
2537
];
2638
}
2739

0 commit comments

Comments
 (0)