2
2
/** */
3
3
import { Ng2StateDeclaration } from "./interface" ;
4
4
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 ,
6
6
} from "@angular/core" ;
7
- import { CommonModule , LocationStrategy , HashLocationStrategy , PathLocationStrategy } from "@angular/common" ;
7
+ import { CommonModule , LocationStrategy , HashLocationStrategy , PathLocationStrategy , isPlatformServer } from "@angular/common" ;
8
8
import { _UIROUTER_DIRECTIVES } from "./directives/directives" ;
9
9
import { UIView } from "./directives/uiView" ;
10
- import { UrlRuleHandlerFn , TargetState , TargetStateDef , UIRouter } from "@uirouter/core" ;
10
+ import { UrlRuleHandlerFn , TargetState , TargetStateDef , UIRouter , TransitionService } from "@uirouter/core" ;
11
11
import { _UIROUTER_INSTANCE_PROVIDERS , _UIROUTER_SERVICE_PROVIDERS } from "./providers" ;
12
12
13
13
import { ROUTES } from "@angular/router" ;
@@ -16,12 +16,24 @@ import { ROUTES } from "@angular/router";
16
16
/** @hidden */ export const UIROUTER_STATES = new InjectionToken ( "UIRouter States" ) ;
17
17
// /** @hidden */ export const ROUTES = UIROUTER_STATES;
18
18
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
+
19
30
export function makeRootProviders ( module : StatesModule ) : Provider [ ] {
20
31
return [
21
32
{ provide : UIROUTER_ROOT_MODULE , useValue : module , multi : true } ,
22
33
{ provide : UIROUTER_MODULE_TOKEN , useValue : module , multi : true } ,
23
34
{ provide : ROUTES , useValue : module . states || [ ] , multi : true } ,
24
35
{ provide : ANALYZE_FOR_ENTRY_COMPONENTS , useValue : module . states || [ ] , multi : true } ,
36
+ { provide : APP_INITIALIZER , useFactory : onTransitionReady , deps : [ TransitionService , PLATFORM_ID ] , multi : true } ,
25
37
] ;
26
38
}
27
39
0 commit comments