@@ -19,32 +19,39 @@ export { NSEmptyOutletComponent } from "./ns-empty-outlet.component";
1919
2020export type LocationState = LocationState ;
2121
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+
2238@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 ] ,
3741 imports : [ RouterModule , NativeScriptCommonModule ] ,
38- exports : [ RouterModule , NSRouterLink , NSRouterLinkActive , PageRouterOutlet , NSEmptyOutletComponent ] ,
42+ exports : [ RouterModule , ... ROUTER_DIRECTIVES ] ,
3943 schemas : [ NO_ERRORS_SCHEMA ] ,
4044} )
4145export 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+ } ;
4451 }
4552
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 } ;
4855 }
4956}
5057
0 commit comments