@@ -19,32 +19,39 @@ export { NSEmptyOutletComponent } from "./ns-empty-outlet.component";
19
19
20
20
export type LocationState = LocationState ;
21
21
22
+ const ROUTER_DIRECTIVES = [ NSRouterLink , NSRouterLinkActive , PageRouterOutlet , NSEmptyOutletComponent ] ;
23
+
24
+ const NS_ROUTER_PROVIDERS = [
25
+ {
26
+ provide : NSLocationStrategy ,
27
+ useFactory : provideLocationStrategy ,
28
+ deps : [ [ NSLocationStrategy , new Optional ( ) , new SkipSelf ( ) ] , FrameService ] ,
29
+ } ,
30
+ { provide : LocationStrategy , useExisting : NSLocationStrategy } ,
31
+ NativescriptPlatformLocation ,
32
+ { provide : PlatformLocation , useClass : NativescriptPlatformLocation } ,
33
+ RouterExtensions ,
34
+ NSRouteReuseStrategy ,
35
+ { provide : RouteReuseStrategy , useExisting : NSRouteReuseStrategy } ,
36
+ ] ;
37
+
22
38
@NgModule ( {
23
- declarations : [ NSRouterLink , NSRouterLinkActive , PageRouterOutlet , NSEmptyOutletComponent ] ,
24
- providers : [
25
- {
26
- provide : NSLocationStrategy ,
27
- useFactory : provideLocationStrategy ,
28
- deps : [ [ NSLocationStrategy , new Optional ( ) , new SkipSelf ( ) ] , FrameService ] ,
29
- } ,
30
- { provide : LocationStrategy , useExisting : NSLocationStrategy } ,
31
- NativescriptPlatformLocation ,
32
- { provide : PlatformLocation , useClass : NativescriptPlatformLocation } ,
33
- RouterExtensions ,
34
- NSRouteReuseStrategy ,
35
- { provide : RouteReuseStrategy , useExisting : NSRouteReuseStrategy } ,
36
- ] ,
39
+ declarations : ROUTER_DIRECTIVES ,
40
+ entryComponents : [ NSEmptyOutletComponent ] ,
37
41
imports : [ RouterModule , NativeScriptCommonModule ] ,
38
- exports : [ RouterModule , NSRouterLink , NSRouterLinkActive , PageRouterOutlet , NSEmptyOutletComponent ] ,
42
+ exports : [ RouterModule , ... ROUTER_DIRECTIVES ] ,
39
43
schemas : [ NO_ERRORS_SCHEMA ] ,
40
44
} )
41
45
export class NativeScriptRouterModule {
42
- static forRoot ( routes : Routes , config ?: ExtraOptions ) : ModuleWithProviders {
43
- return RouterModule . forRoot ( routes , config ) ;
46
+ static forRoot ( routes : Routes , config ?: ExtraOptions ) : ModuleWithProviders < NativeScriptRouterModule > {
47
+ return {
48
+ ngModule : NativeScriptRouterModule ,
49
+ providers : [ ...RouterModule . forRoot ( routes , config ) . providers , ...NS_ROUTER_PROVIDERS ]
50
+ } ;
44
51
}
45
52
46
- static forChild ( routes : Routes ) : ModuleWithProviders {
47
- return RouterModule . forChild ( routes ) ;
53
+ static forChild ( routes : Routes ) : ModuleWithProviders < NativeScriptRouterModule > {
54
+ return { ngModule : NativeScriptRouterModule , providers : RouterModule . forChild ( routes ) . providers } ;
48
55
}
49
56
}
50
57
0 commit comments