-
-
Notifications
You must be signed in to change notification settings - Fork 241
/
router.module.ts
60 lines (56 loc) · 2.85 KB
/
router.module.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { NgModule, ModuleWithProviders, NO_ERRORS_SCHEMA, Optional, SkipSelf } from '@angular/core';
import { RouterModule, Routes, ExtraOptions, RouteReuseStrategy } from '@angular/router';
import { LocationStrategy, PlatformLocation } from '@angular/common';
import { NSRouterLink } from './ns-router-link';
import { NSRouterLinkActive } from './ns-router-link-active';
import { PageRouterOutlet } from './page-router-outlet';
import { NSLocationStrategy } from './ns-location-strategy';
import { NativescriptPlatformLocation } from './ns-platform-location';
import { NSRouteReuseStrategy } from './ns-route-reuse-strategy';
import { RouterExtensions } from './router-extensions';
import { NativeScriptCommonModule } from '../common';
import { FrameService } from '../frame.service';
import { NSEmptyOutletComponent } from './ns-empty-outlet.component';
export { PageRoute } from './page-router-outlet';
export { RouterExtensions } from './router-extensions';
export { NSModuleFactoryLoader } from './ns-module-factory-loader';
export { Outlet, NavigationOptions, LocationState, defaultNavOptions } from './ns-location-utils';
export { NSRouterLink } from './ns-router-link';
export { NSRouterLinkActive } from './ns-router-link-active';
export { PageRouterOutlet } from './page-router-outlet';
export { NSLocationStrategy } from './ns-location-strategy';
export { NSEmptyOutletComponent } from './ns-empty-outlet.component';
export function provideLocationStrategy(locationStrategy: NSLocationStrategy, frameService: FrameService): NSLocationStrategy {
return locationStrategy ? locationStrategy : new NSLocationStrategy(frameService);
}
@NgModule({
declarations: [NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent],
entryComponents: [NSEmptyOutletComponent],
imports: [RouterModule, NativeScriptCommonModule],
exports: [RouterModule, NSRouterLink, NSRouterLinkActive, PageRouterOutlet, NSEmptyOutletComponent],
schemas: [NO_ERRORS_SCHEMA],
})
export class NativeScriptRouterModule {
static forRoot(routes: Routes, config?: ExtraOptions): ModuleWithProviders<NativeScriptRouterModule> {
return {
ngModule: NativeScriptRouterModule,
providers: [
...RouterModule.forRoot(routes, config).providers,
{
provide: NSLocationStrategy,
useFactory: provideLocationStrategy,
deps: [[NSLocationStrategy, new Optional(), new SkipSelf()], FrameService],
},
{ provide: LocationStrategy, useExisting: NSLocationStrategy },
NativescriptPlatformLocation,
{ provide: PlatformLocation, useExisting: NativescriptPlatformLocation },
RouterExtensions,
NSRouteReuseStrategy,
{ provide: RouteReuseStrategy, useExisting: NSRouteReuseStrategy },
],
};
}
static forChild(routes: Routes): ModuleWithProviders<NativeScriptRouterModule> {
return { ngModule: NativeScriptRouterModule, providers: RouterModule.forChild(routes).providers };
}
}