@@ -2,7 +2,7 @@ import { Injectable } from "@angular/core";
2
2
import { LocationStrategy } from "@angular/common" ;
3
3
import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree } from "@angular/router" ;
4
4
import { routerLog } from "../trace" ;
5
- import { NavigationTransition } from "tns-core-modules/ui/frame" ;
5
+ import { NavigationTransition , Frame } from "tns-core-modules/ui/frame" ;
6
6
import { isPresent } from "../lang-facade" ;
7
7
import { FrameService } from "../platform-providers" ;
8
8
@@ -77,7 +77,7 @@ export class NSLocationStrategy extends LocationStrategy {
77
77
}
78
78
79
79
pushState ( state : any , title : string , url : string , queryParams : string ) : void {
80
- routerLog ( "NSLocationStrategy.pushState state: " +
80
+ routerLog ( "NSLocationStrategy.pushState state: " +
81
81
`${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
82
82
this . pushStateInternal ( state , title , url , queryParams ) ;
83
83
}
@@ -240,7 +240,9 @@ export class NSLocationStrategy extends LocationStrategy {
240
240
241
241
private callPopState ( state : LocationState , pop : boolean = true ) {
242
242
const urlSerializer = new DefaultUrlSerializer ( ) ;
243
- if ( state ) {
243
+ const rootOutlet = this . currentUrlTree . root . children [ this . currentOutlet ] ;
244
+
245
+ if ( state && rootOutlet ) {
244
246
this . currentUrlTree . root . children [ this . currentOutlet ] = state . segmentGroup ;
245
247
} else {
246
248
// when closing modal view there are scenarios (e.g. root viewContainerRef) when we need
@@ -283,13 +285,20 @@ export class NSLocationStrategy extends LocationStrategy {
283
285
}
284
286
285
287
// Methods for syncing with page navigation in PageRouterOutlet
286
- public _beginBackPageNavigation ( name : string ) {
288
+ public _beginBackPageNavigation ( name : string , frame : Frame ) {
287
289
routerLog ( "NSLocationStrategy.startGoBack()" ) ;
288
290
if ( this . _isPageNavigationBack ) {
289
291
throw new Error ( "Calling startGoBack while going back." ) ;
290
292
}
291
293
this . _isPageNavigationBack = true ;
292
- this . currentOutlet = name ;
294
+
295
+ let { cachedFrame, hasDuplicateOutlet } = this . frameService . findFrame ( frame , name ) ;
296
+
297
+ if ( cachedFrame ) {
298
+ this . currentOutlet = cachedFrame . rootOutlet ;
299
+ } else if ( ! hasDuplicateOutlet ) {
300
+ this . currentOutlet = name ;
301
+ }
293
302
}
294
303
295
304
public _finishBackPageNavigation ( ) {
@@ -304,9 +313,12 @@ export class NSLocationStrategy extends LocationStrategy {
304
313
return this . _isPageNavigationBack ;
305
314
}
306
315
307
- public _beginModalNavigation ( ) : void {
316
+ public _beginModalNavigation ( frame : Frame ) : void {
308
317
routerLog ( "NSLocationStrategy._beginModalNavigation()" ) ;
309
- const lastState = this . peekState ( this . currentOutlet ) ;
318
+
319
+ let { cachedFrameRootOutlet } = this . frameService . findFrame ( frame ) ;
320
+
321
+ const lastState = this . peekState ( cachedFrameRootOutlet || this . currentOutlet ) ;
310
322
311
323
if ( lastState ) {
312
324
lastState . isModalNavigation = true ;
@@ -333,19 +345,30 @@ export class NSLocationStrategy extends LocationStrategy {
333
345
this . _isModalClosing = false ;
334
346
}
335
347
336
- public _beginPageNavigation ( name : string ) : NavigationOptions {
348
+ public _beginPageNavigation ( name : string , frame : Frame ) : NavigationOptions {
337
349
routerLog ( "NSLocationStrategy._beginPageNavigation()" ) ;
338
- const lastState = this . peekState ( name ) ;
350
+
351
+ let { cachedFrame, hasDuplicateOutlet } = this . frameService . findFrame ( frame , name ) ;
352
+
353
+ if ( cachedFrame ) {
354
+ this . currentOutlet = cachedFrame . rootOutlet ;
355
+ } else {
356
+ if ( ! hasDuplicateOutlet ) {
357
+ this . currentOutlet = name ;
358
+ }
359
+
360
+ this . frameService . addFrame ( frame , name , this . currentOutlet ) ;
361
+ }
362
+
363
+ const lastState = this . peekState ( this . currentOutlet ) ;
339
364
if ( lastState ) {
340
365
lastState . isPageNavigation = true ;
341
366
}
342
367
343
- this . currentOutlet = name ;
344
-
345
368
const navOptions = this . _currentNavigationOptions || defaultNavOptions ;
346
369
if ( navOptions . clearHistory ) {
347
370
routerLog ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
348
- this . statesByOutlet [ name ] = [ lastState ] ;
371
+ this . statesByOutlet [ this . currentOutlet ] = [ lastState ] ;
349
372
}
350
373
351
374
this . _currentNavigationOptions = undefined ;
0 commit comments