1
1
import { Injectable } from "@angular/core" ;
2
2
import { LocationStrategy } from "@angular/common" ;
3
- import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree } from "@angular/router" ;
3
+ import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot } from "@angular/router" ;
4
4
import { routerLog , routerError , isLogEnabled } from "../trace" ;
5
5
import { NavigationTransition , Frame } from "tns-core-modules/ui/frame" ;
6
6
import { isPresent } from "../lang-facade" ;
@@ -88,6 +88,7 @@ export interface LocationState {
88
88
segmentGroup : UrlSegmentGroup ;
89
89
isRootSegmentGroup : boolean ;
90
90
isPageNavigation : boolean ;
91
+ frame ?: Frame ;
91
92
}
92
93
93
94
@Injectable ( )
@@ -162,7 +163,7 @@ export class NSLocationStrategy extends LocationStrategy {
162
163
if ( ! Object . keys ( urlTreeRoot . children ) . length ) {
163
164
const segmentGroup = this . currentUrlTree && this . currentUrlTree . root ;
164
165
const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , "primary" ) ;
165
- const outlet = this . findOutletByKey ( outletKey ) ;
166
+ const outlet = this . findOutlet ( outletKey ) ;
166
167
167
168
if ( outlet && this . updateStates ( outlet , segmentGroup ) ) {
168
169
this . currentOutlet = outlet ; // If states updated
@@ -186,12 +187,12 @@ export class NSLocationStrategy extends LocationStrategy {
186
187
187
188
const outletPath = this . getSegmentGroupFullPath ( currentTree ) ;
188
189
let outletKey = this . getOutletKey ( outletPath , outletName ) ;
189
- let outlet = this . findOutletByKey ( outletKey ) ;
190
+ let outlet = this . findOutlet ( outletKey ) ;
190
191
191
192
const parentOutletName = currentTree . outlet || "" ;
192
193
const parentOutletPath = this . getSegmentGroupFullPath ( currentTree . parent ) ;
193
194
const parentOutletKey = this . getOutletKey ( parentOutletPath , parentOutletName ) ;
194
- const parentOutlet = this . findOutletByKey ( parentOutletKey ) ;
195
+ const parentOutlet = this . findOutlet ( parentOutletKey ) ;
195
196
196
197
const containsLastState = outlet && outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
197
198
if ( ! outlet ) {
@@ -237,7 +238,7 @@ export class NSLocationStrategy extends LocationStrategy {
237
238
throw new Error ( "NSLocationStrategy.forward() - not implemented" ) ;
238
239
}
239
240
240
- back ( outlet ?: Outlet ) : void {
241
+ back ( outlet ?: Outlet , frame ?: Frame ) : void {
241
242
this . currentOutlet = outlet || this . currentOutlet ;
242
243
243
244
if ( this . currentOutlet . isPageNavigationBack ) {
@@ -247,6 +248,13 @@ export class NSLocationStrategy extends LocationStrategy {
247
248
let state = states . pop ( ) ;
248
249
let count = 1 ;
249
250
251
+ if ( frame ) {
252
+ while ( state . frame !== frame ) {
253
+ state = states . pop ( ) ;
254
+ count ++ ;
255
+ }
256
+ }
257
+
250
258
while ( ! state . isPageNavigation ) {
251
259
state = states . pop ( ) ;
252
260
count ++ ;
@@ -447,9 +455,15 @@ export class NSLocationStrategy extends LocationStrategy {
447
455
return this . outlets ;
448
456
}
449
457
450
- updateOutletFrame ( outlet : Outlet , frame : Frame ) {
458
+ updateOutletFrame ( outlet : Outlet , frame : Frame , isEmptyOutletFrame : boolean ) {
459
+ const lastState = outlet . peekState ( ) ;
460
+
461
+ if ( lastState && ! lastState . frame && ! isEmptyOutletFrame ) {
462
+ lastState . frame = frame ;
463
+ }
464
+
451
465
if ( ! outlet . containsFrame ( frame ) ) {
452
- outlet . frames . push ( frame ) ;
466
+ outlet . frames . push ( frame ) ;
453
467
}
454
468
this . currentOutlet = outlet ;
455
469
}
@@ -547,12 +561,17 @@ export class NSLocationStrategy extends LocationStrategy {
547
561
} ) ;
548
562
}
549
563
550
- findOutletByOutletPath ( pathByOutlets : string ) : Outlet {
551
- return this . outlets . find ( ( outlet ) => outlet . pathByOutlets === pathByOutlets ) ;
552
- }
564
+ findOutlet ( outletKey : string , activatedRouteSnapshot ?: ActivatedRouteSnapshot ) : Outlet {
565
+ let outlet : Outlet = this . outlets . find ( ( currentOutlet ) => currentOutlet . outletKeys . indexOf ( outletKey ) > - 1 ) ;
553
566
554
- findOutletByKey ( outletKey : string ) : Outlet {
555
- return this . outlets . find ( ( outlet ) => outlet . outletKeys . indexOf ( outletKey ) > - 1 ) ;
567
+ // No Outlet with the given outletKey could happen when using nested unnamed p-r-o
568
+ // primary -> primary -> prymary
569
+ if ( ! outlet && activatedRouteSnapshot ) {
570
+ const pathByOutlets = this . getPathByOutlets ( activatedRouteSnapshot ) ;
571
+ outlet = this . outlets . find ( ( currentOutlet ) => currentOutlet . pathByOutlets === pathByOutlets ) ;
572
+ }
573
+
574
+ return outlet ;
556
575
}
557
576
558
577
private getOutletByFrame ( frame : Frame ) : Outlet {
0 commit comments