1
- import { Inject , Injectable , Optional } from '@angular/core' ;
2
1
import { LocationChangeEvent , LocationStrategy } from '@angular/common' ;
3
- import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot , Params } from '@angular/router' ;
2
+ import { Inject , Injectable , Optional } from '@angular/core' ;
3
+ import { ActivatedRouteSnapshot , DefaultUrlSerializer , Params , UrlSegmentGroup , UrlTree } from '@angular/router' ;
4
4
import { Frame } from '@nativescript/core' ;
5
+ import { START_PATH } from '../../tokens' ;
5
6
import { NativeScriptDebug } from '../../trace' ;
6
- import { isPresent } from '../../utils/lang-facade' ;
7
7
import { FrameService } from '../frame.service' ;
8
- import { Outlet , NavigationOptions , LocationState , defaultNavOptions } from './ns-location-utils' ;
9
- import { START_PATH } from '../../tokens' ;
8
+ import { defaultNavOptions , LocationState , NavigationOptions , Outlet } from './ns-location-utils' ;
10
9
11
10
@Injectable ( {
12
11
providedIn : 'root' ,
@@ -16,7 +15,6 @@ export class NSLocationStrategy extends LocationStrategy {
16
15
private currentOutlet : Outlet ;
17
16
18
17
private popStateCallbacks = new Array < ( _ : any ) => any > ( ) ;
19
- private _currentNavigationOptions : NavigationOptions ;
20
18
private currentUrlTree : UrlTree ;
21
19
22
20
public _modalNavigationDepth = 0 ;
@@ -42,8 +40,8 @@ export class NSLocationStrategy extends LocationStrategy {
42
40
return '/' ;
43
41
}
44
42
45
- let tree = this . currentUrlTree ;
46
- let changedOutlet = this . getSegmentGroupByOutlet ( this . currentOutlet ) ;
43
+ const tree = this . currentUrlTree ;
44
+ const changedOutlet = this . getSegmentGroupByOutlet ( this . currentOutlet ) ;
47
45
48
46
// Handle case where the user declares a component at path "/".
49
47
// The url serializer doesn't parse this url as having a primary outlet.
@@ -110,7 +108,7 @@ export class NSLocationStrategy extends LocationStrategy {
110
108
currentSegmentGroup . root = urlTreeRoot ;
111
109
112
110
const outletPath = this . getSegmentGroupFullPath ( currentTree ) ;
113
- let outletKey = this . getOutletKey ( outletPath , outletName ) ;
111
+ const outletKey = this . getOutletKey ( outletPath , outletName ) ;
114
112
let outlet = this . findOutlet ( outletKey ) ;
115
113
116
114
const parentOutletName = currentTree . outlet || '' ;
@@ -188,7 +186,7 @@ export class NSLocationStrategy extends LocationStrategy {
188
186
}
189
187
this . callPopState ( state , true ) ;
190
188
} else {
191
- let state = this . currentOutlet . peekState ( ) ;
189
+ const state = this . currentOutlet . peekState ( ) ;
192
190
if ( state && state . isPageNavigation ) {
193
191
// This was a page navigation - so navigate through frame.
194
192
if ( NativeScriptDebug . isLogEnabled ( ) ) {
@@ -237,7 +235,7 @@ export class NSLocationStrategy extends LocationStrategy {
237
235
private callPopState ( state : LocationState , pop : boolean = true , outlet ?: Outlet ) {
238
236
outlet = outlet || this . currentOutlet ;
239
237
const urlSerializer = new DefaultUrlSerializer ( ) ;
240
- let changedOutlet = this . getSegmentGroupByOutlet ( outlet ) ;
238
+ const changedOutlet = this . getSegmentGroupByOutlet ( outlet ) ;
241
239
242
240
if ( state && changedOutlet ) {
243
241
this . updateSegmentGroup ( this . currentUrlTree . root , changedOutlet , state . segmentGroup ) ;
@@ -249,7 +247,7 @@ export class NSLocationStrategy extends LocationStrategy {
249
247
250
248
const url = urlSerializer . serialize ( this . currentUrlTree ) ;
251
249
const change : LocationChangeEvent = { state, type : 'popstate' } ;
252
- for ( let fn of this . popStateCallbacks ) {
250
+ for ( const fn of this . popStateCallbacks ) {
253
251
fn ( change ) ;
254
252
}
255
253
}
@@ -359,7 +357,7 @@ export class NSLocationStrategy extends LocationStrategy {
359
357
}
360
358
}
361
359
362
- public _beginPageNavigation ( frame : Frame ) : NavigationOptions {
360
+ public _beginPageNavigation ( frame : Frame , options ?: NavigationOptions ) : NavigationOptions {
363
361
if ( NativeScriptDebug . isLogEnabled ( ) ) {
364
362
NativeScriptDebug . routerLog ( 'NSLocationStrategy._beginPageNavigation()' ) ;
365
363
}
@@ -371,31 +369,17 @@ export class NSLocationStrategy extends LocationStrategy {
371
369
lastState . isPageNavigation = true ;
372
370
}
373
371
374
- const navOptions = this . _currentNavigationOptions || defaultNavOptions ;
372
+ const navOptions = options || defaultNavOptions ;
373
+
375
374
if ( navOptions . clearHistory ) {
376
375
if ( NativeScriptDebug . isLogEnabled ( ) ) {
377
376
NativeScriptDebug . routerLog ( 'NSLocationStrategy._beginPageNavigation clearing states history' ) ;
378
377
}
379
378
this . currentOutlet . states = [ lastState ] ;
380
379
}
381
-
382
- this . _currentNavigationOptions = undefined ;
383
380
return navOptions ;
384
381
}
385
382
386
- public _setNavigationOptions ( options : NavigationOptions ) {
387
- this . _currentNavigationOptions = {
388
- clearHistory : isPresent ( options . clearHistory ) ? options . clearHistory : false ,
389
- animated : isPresent ( options . animated ) ? options . animated : true ,
390
- transition : options . transition ,
391
- replaceUrl : options . replaceUrl ,
392
- } ;
393
-
394
- if ( NativeScriptDebug . isLogEnabled ( ) ) {
395
- NativeScriptDebug . routerLog ( 'NSLocationStrategy._setNavigationOptions(' + `${ JSON . stringify ( this . _currentNavigationOptions ) } )` ) ;
396
- }
397
- }
398
-
399
383
public _getOutlets ( ) : Array < Outlet > {
400
384
return this . outlets ;
401
385
}
@@ -501,7 +485,7 @@ export class NSLocationStrategy extends LocationStrategy {
501
485
502
486
findOutlet ( outletKey : string , activatedRouteSnapshot ?: ActivatedRouteSnapshot ) : Outlet {
503
487
let outlet : Outlet = this . outlets . find ( ( currentOutlet ) => {
504
- let equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
488
+ const equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
505
489
return equalModalDepth && currentOutlet . outletKeys . indexOf ( outletKey ) > - 1 ;
506
490
} ) ;
507
491
@@ -510,7 +494,7 @@ export class NSLocationStrategy extends LocationStrategy {
510
494
if ( ! outlet && activatedRouteSnapshot ) {
511
495
const pathByOutlets = this . getPathByOutlets ( activatedRouteSnapshot ) ;
512
496
outlet = this . outlets . find ( ( currentOutlet ) => {
513
- let equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
497
+ const equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
514
498
return equalModalDepth && currentOutlet . pathByOutlets === pathByOutlets ;
515
499
} ) ;
516
500
}
@@ -520,7 +504,7 @@ export class NSLocationStrategy extends LocationStrategy {
520
504
521
505
private findOutletByModal ( modalNavigation : number , isShowingModal ?: boolean ) : Outlet {
522
506
return this . outlets . find ( ( outlet ) => {
523
- let equalModalDepth = outlet . modalNavigationDepth === modalNavigation ;
507
+ const equalModalDepth = outlet . modalNavigationDepth === modalNavigation ;
524
508
return isShowingModal ? equalModalDepth && outlet . showingModal : equalModalDepth ;
525
509
} ) ;
526
510
}
0 commit comments