1- import { Inject , Injectable , Optional } from '@angular/core' ;
21import { 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' ;
44import { Frame } from '@nativescript/core' ;
5+ import { START_PATH } from '../../tokens' ;
56import { NativeScriptDebug } from '../../trace' ;
6- import { isPresent } from '../../utils/lang-facade' ;
77import { 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' ;
109
1110@Injectable ( {
1211 providedIn : 'root' ,
@@ -16,7 +15,6 @@ export class NSLocationStrategy extends LocationStrategy {
1615 private currentOutlet : Outlet ;
1716
1817 private popStateCallbacks = new Array < ( _ : any ) => any > ( ) ;
19- private _currentNavigationOptions : NavigationOptions ;
2018 private currentUrlTree : UrlTree ;
2119
2220 public _modalNavigationDepth = 0 ;
@@ -42,8 +40,8 @@ export class NSLocationStrategy extends LocationStrategy {
4240 return '/' ;
4341 }
4442
45- let tree = this . currentUrlTree ;
46- let changedOutlet = this . getSegmentGroupByOutlet ( this . currentOutlet ) ;
43+ const tree = this . currentUrlTree ;
44+ const changedOutlet = this . getSegmentGroupByOutlet ( this . currentOutlet ) ;
4745
4846 // Handle case where the user declares a component at path "/".
4947 // The url serializer doesn't parse this url as having a primary outlet.
@@ -110,7 +108,7 @@ export class NSLocationStrategy extends LocationStrategy {
110108 currentSegmentGroup . root = urlTreeRoot ;
111109
112110 const outletPath = this . getSegmentGroupFullPath ( currentTree ) ;
113- let outletKey = this . getOutletKey ( outletPath , outletName ) ;
111+ const outletKey = this . getOutletKey ( outletPath , outletName ) ;
114112 let outlet = this . findOutlet ( outletKey ) ;
115113
116114 const parentOutletName = currentTree . outlet || '' ;
@@ -188,7 +186,7 @@ export class NSLocationStrategy extends LocationStrategy {
188186 }
189187 this . callPopState ( state , true ) ;
190188 } else {
191- let state = this . currentOutlet . peekState ( ) ;
189+ const state = this . currentOutlet . peekState ( ) ;
192190 if ( state && state . isPageNavigation ) {
193191 // This was a page navigation - so navigate through frame.
194192 if ( NativeScriptDebug . isLogEnabled ( ) ) {
@@ -237,7 +235,7 @@ export class NSLocationStrategy extends LocationStrategy {
237235 private callPopState ( state : LocationState , pop : boolean = true , outlet ?: Outlet ) {
238236 outlet = outlet || this . currentOutlet ;
239237 const urlSerializer = new DefaultUrlSerializer ( ) ;
240- let changedOutlet = this . getSegmentGroupByOutlet ( outlet ) ;
238+ const changedOutlet = this . getSegmentGroupByOutlet ( outlet ) ;
241239
242240 if ( state && changedOutlet ) {
243241 this . updateSegmentGroup ( this . currentUrlTree . root , changedOutlet , state . segmentGroup ) ;
@@ -249,7 +247,7 @@ export class NSLocationStrategy extends LocationStrategy {
249247
250248 const url = urlSerializer . serialize ( this . currentUrlTree ) ;
251249 const change : LocationChangeEvent = { state, type : 'popstate' } ;
252- for ( let fn of this . popStateCallbacks ) {
250+ for ( const fn of this . popStateCallbacks ) {
253251 fn ( change ) ;
254252 }
255253 }
@@ -359,7 +357,7 @@ export class NSLocationStrategy extends LocationStrategy {
359357 }
360358 }
361359
362- public _beginPageNavigation ( frame : Frame ) : NavigationOptions {
360+ public _beginPageNavigation ( frame : Frame , options ?: NavigationOptions ) : NavigationOptions {
363361 if ( NativeScriptDebug . isLogEnabled ( ) ) {
364362 NativeScriptDebug . routerLog ( 'NSLocationStrategy._beginPageNavigation()' ) ;
365363 }
@@ -371,31 +369,17 @@ export class NSLocationStrategy extends LocationStrategy {
371369 lastState . isPageNavigation = true ;
372370 }
373371
374- const navOptions = this . _currentNavigationOptions || defaultNavOptions ;
372+ const navOptions = options || defaultNavOptions ;
373+
375374 if ( navOptions . clearHistory ) {
376375 if ( NativeScriptDebug . isLogEnabled ( ) ) {
377376 NativeScriptDebug . routerLog ( 'NSLocationStrategy._beginPageNavigation clearing states history' ) ;
378377 }
379378 this . currentOutlet . states = [ lastState ] ;
380379 }
381-
382- this . _currentNavigationOptions = undefined ;
383380 return navOptions ;
384381 }
385382
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-
399383 public _getOutlets ( ) : Array < Outlet > {
400384 return this . outlets ;
401385 }
@@ -501,7 +485,7 @@ export class NSLocationStrategy extends LocationStrategy {
501485
502486 findOutlet ( outletKey : string , activatedRouteSnapshot ?: ActivatedRouteSnapshot ) : Outlet {
503487 let outlet : Outlet = this . outlets . find ( ( currentOutlet ) => {
504- let equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
488+ const equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
505489 return equalModalDepth && currentOutlet . outletKeys . indexOf ( outletKey ) > - 1 ;
506490 } ) ;
507491
@@ -510,7 +494,7 @@ export class NSLocationStrategy extends LocationStrategy {
510494 if ( ! outlet && activatedRouteSnapshot ) {
511495 const pathByOutlets = this . getPathByOutlets ( activatedRouteSnapshot ) ;
512496 outlet = this . outlets . find ( ( currentOutlet ) => {
513- let equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
497+ const equalModalDepth = currentOutlet . modalNavigationDepth === this . _modalNavigationDepth ;
514498 return equalModalDepth && currentOutlet . pathByOutlets === pathByOutlets ;
515499 } ) ;
516500 }
@@ -520,7 +504,7 @@ export class NSLocationStrategy extends LocationStrategy {
520504
521505 private findOutletByModal ( modalNavigation : number , isShowingModal ?: boolean ) : Outlet {
522506 return this . outlets . find ( ( outlet ) => {
523- let equalModalDepth = outlet . modalNavigationDepth === modalNavigation ;
507+ const equalModalDepth = outlet . modalNavigationDepth === modalNavigation ;
524508 return isShowingModal ? equalModalDepth && outlet . showingModal : equalModalDepth ;
525509 } ) ;
526510 }
0 commit comments