11import { Injectable } from "@angular/core" ;
22import { LocationStrategy } from "@angular/common" ;
3- import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree } from "@angular/router" ;
3+ import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot } from "@angular/router" ;
44import { routerLog , routerError , isLogEnabled } from "../trace" ;
55import { NavigationTransition , Frame } from "tns-core-modules/ui/frame" ;
66import { isPresent } from "../lang-facade" ;
@@ -88,6 +88,7 @@ export interface LocationState {
8888 segmentGroup : UrlSegmentGroup ;
8989 isRootSegmentGroup : boolean ;
9090 isPageNavigation : boolean ;
91+ frame ?: Frame ;
9192}
9293
9394@Injectable ( )
@@ -162,7 +163,7 @@ export class NSLocationStrategy extends LocationStrategy {
162163 if ( ! Object . keys ( urlTreeRoot . children ) . length ) {
163164 const segmentGroup = this . currentUrlTree && this . currentUrlTree . root ;
164165 const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , "primary" ) ;
165- const outlet = this . findOutletByKey ( outletKey ) ;
166+ const outlet = this . findOutlet ( outletKey ) ;
166167
167168 if ( outlet && this . updateStates ( outlet , segmentGroup ) ) {
168169 this . currentOutlet = outlet ; // If states updated
@@ -186,12 +187,12 @@ export class NSLocationStrategy extends LocationStrategy {
186187
187188 const outletPath = this . getSegmentGroupFullPath ( currentTree ) ;
188189 let outletKey = this . getOutletKey ( outletPath , outletName ) ;
189- let outlet = this . findOutletByKey ( outletKey ) ;
190+ let outlet = this . findOutlet ( outletKey ) ;
190191
191192 const parentOutletName = currentTree . outlet || "" ;
192193 const parentOutletPath = this . getSegmentGroupFullPath ( currentTree . parent ) ;
193194 const parentOutletKey = this . getOutletKey ( parentOutletPath , parentOutletName ) ;
194- const parentOutlet = this . findOutletByKey ( parentOutletKey ) ;
195+ const parentOutlet = this . findOutlet ( parentOutletKey ) ;
195196
196197 const containsLastState = outlet && outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
197198 if ( ! outlet ) {
@@ -237,7 +238,7 @@ export class NSLocationStrategy extends LocationStrategy {
237238 throw new Error ( "NSLocationStrategy.forward() - not implemented" ) ;
238239 }
239240
240- back ( outlet ?: Outlet ) : void {
241+ back ( outlet ?: Outlet , frame ?: Frame ) : void {
241242 this . currentOutlet = outlet || this . currentOutlet ;
242243
243244 if ( this . currentOutlet . isPageNavigationBack ) {
@@ -247,6 +248,13 @@ export class NSLocationStrategy extends LocationStrategy {
247248 let state = states . pop ( ) ;
248249 let count = 1 ;
249250
251+ if ( frame ) {
252+ while ( state . frame !== frame ) {
253+ state = states . pop ( ) ;
254+ count ++ ;
255+ }
256+ }
257+
250258 while ( ! state . isPageNavigation ) {
251259 state = states . pop ( ) ;
252260 count ++ ;
@@ -447,9 +455,15 @@ export class NSLocationStrategy extends LocationStrategy {
447455 return this . outlets ;
448456 }
449457
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+
451465 if ( ! outlet . containsFrame ( frame ) ) {
452- outlet . frames . push ( frame ) ;
466+ outlet . frames . push ( frame ) ;
453467 }
454468 this . currentOutlet = outlet ;
455469 }
@@ -547,12 +561,17 @@ export class NSLocationStrategy extends LocationStrategy {
547561 } ) ;
548562 }
549563
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 ) ;
553566
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 ;
556575 }
557576
558577 private getOutletByFrame ( frame : Frame ) : Outlet {
0 commit comments