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 , Frame } 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
@@ -286,39 +286,38 @@ export class NSLocationStrategy extends LocationStrategy {
286
286
287
287
// Methods for syncing with page navigation in PageRouterOutlet
288
288
public _beginBackPageNavigation ( name : string , frame : Frame ) {
289
- routerLog ( "NSLocationStrategy.startGoBack()" ) ;
290
- if ( this . _isPageNavigationBack ) {
291
- throw new Error ( "Calling startGoBack while going back." ) ;
292
- }
293
- this . _isPageNavigationBack = true ;
294
-
295
- let { cachedFrame } = this . frameService . findFrame ( frame ) ;
296
-
297
- if ( cachedFrame ) {
298
- this . currentOutlet = cachedFrame . rootOutlet ;
299
- } else if ( ! this . frameService . containsOutlet ( name ) ) {
300
- this . currentOutlet = name ;
301
- }
302
- }
289
+ if ( this . _isPageNavigationBack ) {
290
+ log ( "Warn: Attempted to call startGoBack while going back. Ignoring." ) ;
291
+ return ;
292
+ }
293
+ log ( "NSLocationStrategy.startGoBack()" ) ;
294
+ this . _isPageNavigationBack = true ;
295
+
296
+ let { cachedFrame } = this . frameService . findFrame ( frame ) ;
297
+
298
+ if ( cachedFrame ) {
299
+ this . currentOutlet = cachedFrame . rootOutlet ;
300
+ } else if ( ! this . frameService . containsOutlet ( name ) ) {
301
+ this . currentOutlet = name ;
302
+ }
303
+ }
303
304
304
305
public _finishBackPageNavigation ( ) {
305
- routerLog ( "NSLocationStrategy.finishBackPageNavigation()" ) ;
306
306
if ( ! this . _isPageNavigationBack ) {
307
- throw new Error ( "Calling endGoBack while not going back." ) ;
307
+ log ( "Warn: Attempted to call endGoBack while not going back. Ignoring." ) ;
308
+ return ;
308
309
}
310
+ log ( "NSLocationStrategy.finishBackPageNavigation()" ) ;
309
311
this . _isPageNavigationBack = false ;
310
312
}
311
313
312
314
public _isPageNavigatingBack ( ) {
313
315
return this . _isPageNavigationBack ;
314
316
}
315
317
316
- public _beginModalNavigation ( frame : Frame ) : void {
317
- routerLog ( "NSLocationStrategy._beginModalNavigation()" ) ;
318
-
319
- let { cachedFrameRootOutlet } = this . frameService . findFrame ( frame ) ;
320
-
321
- const lastState = this . peekState ( cachedFrameRootOutlet || this . currentOutlet ) ;
318
+ public _beginModalNavigation ( ) : void {
319
+ log ( "NSLocationStrategy._beginModalNavigation()" ) ;
320
+ const lastState = this . peekState ( this . currentOutlet ) ;
322
321
323
322
if ( lastState ) {
324
323
lastState . isModalNavigation = true ;
@@ -328,48 +327,36 @@ export class NSLocationStrategy extends LocationStrategy {
328
327
}
329
328
330
329
public _beginCloseModalNavigation ( ) : void {
331
- routerLog ( "NSLocationStrategy.startCloseModal()" ) ;
332
330
if ( this . _isModalClosing ) {
333
- throw new Error ( "Calling startCloseModal while closing modal." ) ;
331
+ log ( "Warn: Attempted to call startCloseModal while closing modal. Ignoring." ) ;
332
+ return ;
334
333
}
334
+ log ( "NSLocationStrategy.startCloseModal()" ) ;
335
335
this . _isModalClosing = true ;
336
336
}
337
337
338
338
public _finishCloseModalNavigation ( ) {
339
- routerLog ( "NSLocationStrategy.finishCloseModalNavigation()" ) ;
340
339
if ( ! this . _isModalClosing ) {
341
- throw new Error ( "Calling startCloseModal while not closing modal." ) ;
340
+ log ( "Warn: Attempted to call startCloseModal while not closing modal. Ignoring." ) ;
341
+ return ;
342
342
}
343
343
344
+ log ( "NSLocationStrategy.finishCloseModalNavigation()" ) ;
344
345
this . _isModalNavigation = false ;
345
346
this . _isModalClosing = false ;
346
347
}
347
348
348
- public _beginPageNavigation ( name : string , frame : Frame ) : NavigationOptions {
349
- routerLog ( "NSLocationStrategy._beginPageNavigation()" ) ;
350
-
351
- let { cachedFrame } = this . frameService . findFrame ( frame ) ;
352
-
353
- if ( cachedFrame ) {
354
- this . currentOutlet = cachedFrame . rootOutlet ;
355
- } else {
356
- // Changing the current outlet only if navigating in non-cached root outlet.
357
- if ( ! this . frameService . containsOutlet ( name ) && this . statesByOutlet [ name ] /* ensure root outlet exists */ ) {
358
- this . currentOutlet = name ;
359
- }
360
-
361
- this . frameService . addFrame ( frame , name , this . currentOutlet ) ;
362
- }
363
-
364
- const lastState = this . peekState ( this . currentOutlet ) ;
349
+ public _beginPageNavigation ( name : string ) : NavigationOptions {
350
+ log ( "NSLocationStrategy._beginPageNavigation()" ) ;
351
+ const lastState = this . peekState ( name ) ;
365
352
if ( lastState ) {
366
353
lastState . isPageNavigation = true ;
367
354
}
368
355
369
356
const navOptions = this . _currentNavigationOptions || defaultNavOptions ;
370
357
if ( navOptions . clearHistory ) {
371
- routerLog ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
372
- this . statesByOutlet [ this . currentOutlet ] = [ lastState ] ;
358
+ log ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
359
+ this . statesByOutlet [ name ] = [ lastState ] ;
373
360
}
374
361
375
362
this . _currentNavigationOptions = undefined ;
@@ -382,7 +369,7 @@ export class NSLocationStrategy extends LocationStrategy {
382
369
animated : isPresent ( options . animated ) ? options . animated : true ,
383
370
transition : options . transition
384
371
} ;
385
- routerLog ( "NSLocationStrategy._setNavigationOptions(" +
372
+ log ( "NSLocationStrategy._setNavigationOptions(" +
386
373
`${ JSON . stringify ( this . _currentNavigationOptions ) } )` ) ;
387
374
}
388
375
0 commit comments