11import { Injectable } from "@angular/core" ;
22import { LocationStrategy } from "@angular/common" ;
33import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree } from "@angular/router" ;
4- import { routerLog } from "../trace" ;
4+ import { routerLog as log } from "../trace" ;
55import { NavigationTransition } from "tns-core-modules/ui/frame" ;
66import { isPresent } from "../lang-facade" ;
77import { FrameService } from "../platform-providers" ;
@@ -42,7 +42,7 @@ export class NSLocationStrategy extends LocationStrategy {
4242
4343 constructor ( private frameService : FrameService ) {
4444 super ( ) ;
45- routerLog ( "NSLocationStrategy.constructor()" ) ;
45+ log ( "NSLocationStrategy.constructor()" ) ;
4646 }
4747
4848 path ( ) : string {
@@ -67,17 +67,17 @@ export class NSLocationStrategy extends LocationStrategy {
6767
6868 const urlSerializer = new DefaultUrlSerializer ( ) ;
6969 const url = urlSerializer . serialize ( tree ) ;
70- routerLog ( "NSLocationStrategy.path(): " + url ) ;
70+ log ( "NSLocationStrategy.path(): " + url ) ;
7171 return url ;
7272 }
7373
7474 prepareExternalUrl ( internal : string ) : string {
75- routerLog ( "NSLocationStrategy.prepareExternalUrl() internal: " + internal ) ;
75+ log ( "NSLocationStrategy.prepareExternalUrl() internal: " + internal ) ;
7676 return internal ;
7777 }
7878
7979 pushState ( state : any , title : string , url : string , queryParams : string ) : void {
80- routerLog ( "NSLocationStrategy.pushState state: " +
80+ log ( "NSLocationStrategy.pushState state: " +
8181 `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
8282 this . pushStateInternal ( state , title , url , queryParams ) ;
8383 }
@@ -130,7 +130,7 @@ export class NSLocationStrategy extends LocationStrategy {
130130 replaceState ( state : any , title : string , url : string , queryParams : string ) : void {
131131 const states = this . statesByOutlet [ this . currentOutlet ] ;
132132 if ( states && states . length > 0 ) {
133- routerLog ( "NSLocationStrategy.replaceState changing existing state: " +
133+ log ( "NSLocationStrategy.replaceState changing existing state: " +
134134 `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
135135
136136 const tree = this . currentUrlTree ;
@@ -149,7 +149,7 @@ export class NSLocationStrategy extends LocationStrategy {
149149 } ) ;
150150 }
151151 } else {
152- routerLog ( "NSLocationStrategy.replaceState pushing new state: " +
152+ log ( "NSLocationStrategy.replaceState pushing new state: " +
153153 `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
154154 this . pushStateInternal ( state , title , url , queryParams ) ;
155155 }
@@ -186,7 +186,7 @@ export class NSLocationStrategy extends LocationStrategy {
186186 }
187187 }
188188
189- routerLog ( "NSLocationStrategy.back() while closing modal. States popped: " + count ) ;
189+ log ( "NSLocationStrategy.back() while closing modal. States popped: " + count ) ;
190190
191191 if ( state ) {
192192 this . callPopState ( state , true ) ;
@@ -203,19 +203,19 @@ export class NSLocationStrategy extends LocationStrategy {
203203 count ++ ;
204204 }
205205
206- routerLog ( "NSLocationStrategy.back() while navigating back. States popped: " + count ) ;
206+ log ( "NSLocationStrategy.back() while navigating back. States popped: " + count ) ;
207207 this . callPopState ( state , true ) ;
208208 } else {
209209 let state = this . peekState ( this . currentOutlet ) ;
210210 if ( state . isPageNavigation ) {
211211 // This was a page navigation - so navigate through frame.
212- routerLog ( "NSLocationStrategy.back() while not navigating back but top" +
212+ log ( "NSLocationStrategy.back() while not navigating back but top" +
213213 " state is page - will call frame.goBack()" ) ;
214214 const frame = this . frameService . getFrame ( ) ;
215215 frame . goBack ( ) ;
216216 } else {
217217 // Nested navigation - just pop the state
218- routerLog ( "NSLocationStrategy.back() while not navigating back but top" +
218+ log ( "NSLocationStrategy.back() while not navigating back but top" +
219219 " state is not page - just pop" ) ;
220220
221221 this . callPopState ( this . statesByOutlet [ this . currentOutlet ] . pop ( ) , true ) ;
@@ -229,12 +229,12 @@ export class NSLocationStrategy extends LocationStrategy {
229229 }
230230
231231 onPopState ( fn : ( _ : any ) => any ) : void {
232- routerLog ( "NSLocationStrategy.onPopState" ) ;
232+ log ( "NSLocationStrategy.onPopState" ) ;
233233 this . popStateCallbacks . push ( fn ) ;
234234 }
235235
236236 getBaseHref ( ) : string {
237- routerLog ( "NSLocationStrategy.getBaseHref()" ) ;
237+ log ( "NSLocationStrategy.getBaseHref()" ) ;
238238 return "" ;
239239 }
240240
@@ -284,19 +284,21 @@ export class NSLocationStrategy extends LocationStrategy {
284284
285285 // Methods for syncing with page navigation in PageRouterOutlet
286286 public _beginBackPageNavigation ( name : string ) {
287- routerLog ( "NSLocationStrategy.startGoBack()" ) ;
288287 if ( this . _isPageNavigationBack ) {
289- throw new Error ( "Calling startGoBack while going back." ) ;
288+ log ( "Warn: Attempted to call startGoBack while going back. Ignoring." ) ;
289+ return ;
290290 }
291+ log ( "NSLocationStrategy.startGoBack()" ) ;
291292 this . _isPageNavigationBack = true ;
292293 this . currentOutlet = name ;
293294 }
294295
295296 public _finishBackPageNavigation ( ) {
296- routerLog ( "NSLocationStrategy.finishBackPageNavigation()" ) ;
297297 if ( ! this . _isPageNavigationBack ) {
298- throw new Error ( "Calling endGoBack while not going back." ) ;
298+ log ( "Warn: Attempted to call endGoBack while not going back. Ignoring." ) ;
299+ return ;
299300 }
301+ log ( "NSLocationStrategy.finishBackPageNavigation()" ) ;
300302 this . _isPageNavigationBack = false ;
301303 }
302304
@@ -305,7 +307,7 @@ export class NSLocationStrategy extends LocationStrategy {
305307 }
306308
307309 public _beginModalNavigation ( ) : void {
308- routerLog ( "NSLocationStrategy._beginModalNavigation()" ) ;
310+ log ( "NSLocationStrategy._beginModalNavigation()" ) ;
309311 const lastState = this . peekState ( this . currentOutlet ) ;
310312
311313 if ( lastState ) {
@@ -316,25 +318,27 @@ export class NSLocationStrategy extends LocationStrategy {
316318 }
317319
318320 public _beginCloseModalNavigation ( ) : void {
319- routerLog ( "NSLocationStrategy.startCloseModal()" ) ;
320321 if ( this . _isModalClosing ) {
321- throw new Error ( "Calling startCloseModal while closing modal." ) ;
322+ log ( "Warn: Attempted to call startCloseModal while closing modal. Ignoring." ) ;
323+ return ;
322324 }
325+ log ( "NSLocationStrategy.startCloseModal()" ) ;
323326 this . _isModalClosing = true ;
324327 }
325328
326329 public _finishCloseModalNavigation ( ) {
327- routerLog ( "NSLocationStrategy.finishCloseModalNavigation()" ) ;
328330 if ( ! this . _isModalClosing ) {
329- throw new Error ( "Calling startCloseModal while not closing modal." ) ;
331+ log ( "Warn: Attempted to call startCloseModal while not closing modal. Ignoring." ) ;
332+ return ;
330333 }
331334
335+ log ( "NSLocationStrategy.finishCloseModalNavigation()" ) ;
332336 this . _isModalNavigation = false ;
333337 this . _isModalClosing = false ;
334338 }
335339
336340 public _beginPageNavigation ( name : string ) : NavigationOptions {
337- routerLog ( "NSLocationStrategy._beginPageNavigation()" ) ;
341+ log ( "NSLocationStrategy._beginPageNavigation()" ) ;
338342 const lastState = this . peekState ( name ) ;
339343 if ( lastState ) {
340344 lastState . isPageNavigation = true ;
@@ -344,7 +348,7 @@ export class NSLocationStrategy extends LocationStrategy {
344348
345349 const navOptions = this . _currentNavigationOptions || defaultNavOptions ;
346350 if ( navOptions . clearHistory ) {
347- routerLog ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
351+ log ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
348352 this . statesByOutlet [ name ] = [ lastState ] ;
349353 }
350354
@@ -358,7 +362,7 @@ export class NSLocationStrategy extends LocationStrategy {
358362 animated : isPresent ( options . animated ) ? options . animated : true ,
359363 transition : options . transition
360364 } ;
361- routerLog ( "NSLocationStrategy._setNavigationOptions(" +
365+ log ( "NSLocationStrategy._setNavigationOptions(" +
362366 `${ JSON . stringify ( this . _currentNavigationOptions ) } )` ) ;
363367 }
364368
0 commit comments