1
1
import { Injectable } from "@angular/core" ;
2
2
import { LocationStrategy } from "@angular/common" ;
3
3
import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree } from "@angular/router" ;
4
- import { routerLog } from "../trace" ;
4
+ import { routerLog as log } from "../trace" ;
5
5
import { NavigationTransition } from "tns-core-modules/ui/frame" ;
6
6
import { isPresent } from "../lang-facade" ;
7
7
import { FrameService } from "../platform-providers" ;
@@ -42,7 +42,7 @@ export class NSLocationStrategy extends LocationStrategy {
42
42
43
43
constructor ( private frameService : FrameService ) {
44
44
super ( ) ;
45
- routerLog ( "NSLocationStrategy.constructor()" ) ;
45
+ log ( "NSLocationStrategy.constructor()" ) ;
46
46
}
47
47
48
48
path ( ) : string {
@@ -67,17 +67,17 @@ export class NSLocationStrategy extends LocationStrategy {
67
67
68
68
const urlSerializer = new DefaultUrlSerializer ( ) ;
69
69
const url = urlSerializer . serialize ( tree ) ;
70
- routerLog ( "NSLocationStrategy.path(): " + url ) ;
70
+ log ( "NSLocationStrategy.path(): " + url ) ;
71
71
return url ;
72
72
}
73
73
74
74
prepareExternalUrl ( internal : string ) : string {
75
- routerLog ( "NSLocationStrategy.prepareExternalUrl() internal: " + internal ) ;
75
+ log ( "NSLocationStrategy.prepareExternalUrl() internal: " + internal ) ;
76
76
return internal ;
77
77
}
78
78
79
79
pushState ( state : any , title : string , url : string , queryParams : string ) : void {
80
- routerLog ( "NSLocationStrategy.pushState state: " +
80
+ log ( "NSLocationStrategy.pushState state: " +
81
81
`${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
82
82
this . pushStateInternal ( state , title , url , queryParams ) ;
83
83
}
@@ -130,7 +130,7 @@ export class NSLocationStrategy extends LocationStrategy {
130
130
replaceState ( state : any , title : string , url : string , queryParams : string ) : void {
131
131
const states = this . statesByOutlet [ this . currentOutlet ] ;
132
132
if ( states && states . length > 0 ) {
133
- routerLog ( "NSLocationStrategy.replaceState changing existing state: " +
133
+ log ( "NSLocationStrategy.replaceState changing existing state: " +
134
134
`${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
135
135
136
136
const tree = this . currentUrlTree ;
@@ -149,7 +149,7 @@ export class NSLocationStrategy extends LocationStrategy {
149
149
} ) ;
150
150
}
151
151
} else {
152
- routerLog ( "NSLocationStrategy.replaceState pushing new state: " +
152
+ log ( "NSLocationStrategy.replaceState pushing new state: " +
153
153
`${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
154
154
this . pushStateInternal ( state , title , url , queryParams ) ;
155
155
}
@@ -186,7 +186,7 @@ export class NSLocationStrategy extends LocationStrategy {
186
186
}
187
187
}
188
188
189
- routerLog ( "NSLocationStrategy.back() while closing modal. States popped: " + count ) ;
189
+ log ( "NSLocationStrategy.back() while closing modal. States popped: " + count ) ;
190
190
191
191
if ( state ) {
192
192
this . callPopState ( state , true ) ;
@@ -203,19 +203,19 @@ export class NSLocationStrategy extends LocationStrategy {
203
203
count ++ ;
204
204
}
205
205
206
- routerLog ( "NSLocationStrategy.back() while navigating back. States popped: " + count ) ;
206
+ log ( "NSLocationStrategy.back() while navigating back. States popped: " + count ) ;
207
207
this . callPopState ( state , true ) ;
208
208
} else {
209
209
let state = this . peekState ( this . currentOutlet ) ;
210
210
if ( state . isPageNavigation ) {
211
211
// 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" +
213
213
" state is page - will call frame.goBack()" ) ;
214
214
const frame = this . frameService . getFrame ( ) ;
215
215
frame . goBack ( ) ;
216
216
} else {
217
217
// 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" +
219
219
" state is not page - just pop" ) ;
220
220
221
221
this . callPopState ( this . statesByOutlet [ this . currentOutlet ] . pop ( ) , true ) ;
@@ -229,12 +229,12 @@ export class NSLocationStrategy extends LocationStrategy {
229
229
}
230
230
231
231
onPopState ( fn : ( _ : any ) => any ) : void {
232
- routerLog ( "NSLocationStrategy.onPopState" ) ;
232
+ log ( "NSLocationStrategy.onPopState" ) ;
233
233
this . popStateCallbacks . push ( fn ) ;
234
234
}
235
235
236
236
getBaseHref ( ) : string {
237
- routerLog ( "NSLocationStrategy.getBaseHref()" ) ;
237
+ log ( "NSLocationStrategy.getBaseHref()" ) ;
238
238
return "" ;
239
239
}
240
240
@@ -284,19 +284,21 @@ export class NSLocationStrategy extends LocationStrategy {
284
284
285
285
// Methods for syncing with page navigation in PageRouterOutlet
286
286
public _beginBackPageNavigation ( name : string ) {
287
- routerLog ( "NSLocationStrategy.startGoBack()" ) ;
288
287
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 ;
290
290
}
291
+ log ( "NSLocationStrategy.startGoBack()" ) ;
291
292
this . _isPageNavigationBack = true ;
292
293
this . currentOutlet = name ;
293
294
}
294
295
295
296
public _finishBackPageNavigation ( ) {
296
- routerLog ( "NSLocationStrategy.finishBackPageNavigation()" ) ;
297
297
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 ;
299
300
}
301
+ log ( "NSLocationStrategy.finishBackPageNavigation()" ) ;
300
302
this . _isPageNavigationBack = false ;
301
303
}
302
304
@@ -305,7 +307,7 @@ export class NSLocationStrategy extends LocationStrategy {
305
307
}
306
308
307
309
public _beginModalNavigation ( ) : void {
308
- routerLog ( "NSLocationStrategy._beginModalNavigation()" ) ;
310
+ log ( "NSLocationStrategy._beginModalNavigation()" ) ;
309
311
const lastState = this . peekState ( this . currentOutlet ) ;
310
312
311
313
if ( lastState ) {
@@ -316,25 +318,27 @@ export class NSLocationStrategy extends LocationStrategy {
316
318
}
317
319
318
320
public _beginCloseModalNavigation ( ) : void {
319
- routerLog ( "NSLocationStrategy.startCloseModal()" ) ;
320
321
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 ;
322
324
}
325
+ log ( "NSLocationStrategy.startCloseModal()" ) ;
323
326
this . _isModalClosing = true ;
324
327
}
325
328
326
329
public _finishCloseModalNavigation ( ) {
327
- routerLog ( "NSLocationStrategy.finishCloseModalNavigation()" ) ;
328
330
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 ;
330
333
}
331
334
335
+ log ( "NSLocationStrategy.finishCloseModalNavigation()" ) ;
332
336
this . _isModalNavigation = false ;
333
337
this . _isModalClosing = false ;
334
338
}
335
339
336
340
public _beginPageNavigation ( name : string ) : NavigationOptions {
337
- routerLog ( "NSLocationStrategy._beginPageNavigation()" ) ;
341
+ log ( "NSLocationStrategy._beginPageNavigation()" ) ;
338
342
const lastState = this . peekState ( name ) ;
339
343
if ( lastState ) {
340
344
lastState . isPageNavigation = true ;
@@ -344,7 +348,7 @@ export class NSLocationStrategy extends LocationStrategy {
344
348
345
349
const navOptions = this . _currentNavigationOptions || defaultNavOptions ;
346
350
if ( navOptions . clearHistory ) {
347
- routerLog ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
351
+ log ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
348
352
this . statesByOutlet [ name ] = [ lastState ] ;
349
353
}
350
354
@@ -358,7 +362,7 @@ export class NSLocationStrategy extends LocationStrategy {
358
362
animated : isPresent ( options . animated ) ? options . animated : true ,
359
363
transition : options . transition
360
364
} ;
361
- routerLog ( "NSLocationStrategy._setNavigationOptions(" +
365
+ log ( "NSLocationStrategy._setNavigationOptions(" +
362
366
`${ JSON . stringify ( this . _currentNavigationOptions ) } )` ) ;
363
367
}
364
368
0 commit comments