@@ -11,9 +11,12 @@ export class Outlet {
1111 modalNavigationDepth : number ;
1212 parent : Outlet ;
1313 isPageNavigationBack : boolean ;
14+
15+ // More than one key available when using NSEmptyOutletComponent component
16+ // in module that lazy loads children (loadChildren) and has outlet name.
1417 outletKeys : Array < string > ;
1518 pathByOutlets : string ;
16- statesByOutlet : Array < LocationState > = [ ] ;
19+ states : Array < LocationState > = [ ] ;
1720 frame : Frame ;
1821
1922 // Used in reuse-strategy by its children to determine if they should be detached too.
@@ -27,13 +30,13 @@ export class Outlet {
2730 }
2831
2932 peekState ( ) : LocationState {
30- if ( this . statesByOutlet . length > 0 ) {
31- return this . statesByOutlet [ this . statesByOutlet . length - 1 ] ;
33+ if ( this . states . length > 0 ) {
34+ return this . states [ this . states . length - 1 ] ;
3235 }
3336 return null ;
3437 }
3538
36- containsLastState ( stateUrl : string ) : boolean {
39+ containsTopState ( stateUrl : string ) : boolean {
3740 const lastState = this . peekState ( ) ;
3841 return lastState && lastState . segmentGroup . toString ( ) === stateUrl ;
3942 }
@@ -92,7 +95,6 @@ export class NSLocationStrategy extends LocationStrategy {
9295 if ( state . isRootSegmentGroup ) {
9396 tree . root = state . segmentGroup ;
9497 } else if ( changedOutlet ) {
95- // tslint:disable-next-line:max-line-length
9698 this . updateSegmentGroup ( tree . root , changedOutlet , state . segmentGroup ) ;
9799 }
98100
@@ -129,49 +131,49 @@ export class NSLocationStrategy extends LocationStrategy {
129131 // The url serializer doesn't parse this url as having a primary outlet.
130132 const rootOutlet = this . createOutlet ( "primary" , null , null ) ;
131133 this . currentOutlet = rootOutlet ;
132- } else {
133- const queue = [ ] ;
134- queue . push ( urlTreeRoot ) ;
135- let currentTree = queue . shift ( ) ;
136-
137- while ( currentTree ) {
138- Object . keys ( currentTree . children ) . forEach ( outletName => {
139- const currentSegmentGroup = currentTree . children [ outletName ] ;
140- currentSegmentGroup . outlet = outletName ;
141- currentSegmentGroup . root = urlTreeRoot ;
142-
143- let outletKey = this . getSegmentGroupFullPath ( currentTree ) + outletName ;
144- let outlet = this . findOutletByKey ( outletKey ) ;
145- const parentOutletName = currentTree . outlet || "" ;
146- const parentOutletKey = this . getSegmentGroupFullPath ( currentTree . parent ) + parentOutletName ;
147- const parentOutlet = this . findOutletByKey ( parentOutletKey ) ;
148-
149- const containsLastState = outlet && outlet . containsLastState ( currentSegmentGroup . toString ( ) ) ;
150- if ( ! outlet ) {
151- // tslint:disable-next-line:max-line-length
152- outlet = this . createOutlet ( outletKey , currentSegmentGroup , parentOutlet , this . _modalNavigationDepth ) ;
153- this . currentOutlet = outlet ;
154- } else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
155- // Navigation inside modal view.
156- this . upsertModalOutlet ( outlet , currentSegmentGroup ) ;
157- } else {
158- outlet . parent = parentOutlet ;
134+ return ;
135+ }
136+
137+ const queue = [ ] ;
138+ let currentTree = < any > urlTreeRoot ;
139+
140+ while ( currentTree ) {
141+ Object . keys ( currentTree . children ) . forEach ( outletName => {
142+ const currentSegmentGroup = currentTree . children [ outletName ] ;
143+ currentSegmentGroup . outlet = outletName ;
144+ currentSegmentGroup . root = urlTreeRoot ;
145+
146+ let outletKey = this . getSegmentGroupFullPath ( currentTree ) + outletName ;
147+ let outlet = this . findOutletByKey ( outletKey ) ;
148+ const parentOutletName = currentTree . outlet || "" ;
149+ const parentOutletKey = this . getSegmentGroupFullPath ( currentTree . parent ) + parentOutletName ;
150+ const parentOutlet = this . findOutletByKey ( parentOutletKey ) ;
159151
160- if ( this . updateStates ( outlet , currentSegmentGroup ) ) {
161- this . currentOutlet = outlet ; // If states updated
162- }
152+ const containsLastState = outlet && outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
153+ if ( ! outlet ) {
154+ // tslint:disable-next-line:max-line-length
155+ outlet = this . createOutlet ( outletKey , currentSegmentGroup , parentOutlet , this . _modalNavigationDepth ) ;
156+ this . currentOutlet = outlet ;
157+ } else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
158+ // Navigation inside modal view.
159+ this . upsertModalOutlet ( outlet , currentSegmentGroup ) ;
160+ } else {
161+ outlet . parent = parentOutlet ;
162+
163+ if ( this . updateStates ( outlet , currentSegmentGroup ) ) {
164+ this . currentOutlet = outlet ; // If states updated
163165 }
166+ }
164167
165- queue . push ( currentTree . children [ outletName ] ) ;
166- } ) ;
168+ queue . push ( currentSegmentGroup ) ;
169+ } ) ;
167170
168- currentTree = queue . shift ( ) ;
169- }
171+ currentTree = queue . shift ( ) ;
170172 }
171173 }
172174
173175 replaceState ( state : any , title : string , url : string , queryParams : string ) : void {
174- const states = this . currentOutlet && this . currentOutlet . statesByOutlet ;
176+ const states = this . currentOutlet && this . currentOutlet . states ;
175177
176178 if ( states && states . length > 0 ) {
177179 if ( isLogEnabled ( ) ) {
@@ -195,7 +197,7 @@ export class NSLocationStrategy extends LocationStrategy {
195197 this . currentOutlet = outlet || this . currentOutlet ;
196198
197199 if ( this . currentOutlet . isPageNavigationBack ) {
198- const states = this . currentOutlet . statesByOutlet ;
200+ const states = this . currentOutlet . states ;
199201 // We are navigating to the previous page
200202 // clear the stack until we get to a page navigation state
201203 let state = states . pop ( ) ;
@@ -231,14 +233,14 @@ export class NSLocationStrategy extends LocationStrategy {
231233 " state is not page - just pop" ) ;
232234 }
233235
234- this . callPopState ( this . currentOutlet . statesByOutlet . pop ( ) , true ) ;
236+ this . callPopState ( this . currentOutlet . states . pop ( ) , true ) ;
235237 }
236238 }
237239 }
238240
239241 canGoBack ( outlet ?: Outlet ) {
240242 outlet = outlet || this . currentOutlet ;
241- return outlet . statesByOutlet . length > 1 ;
243+ return outlet . states . length > 1 ;
242244 }
243245
244246 onPopState ( fn : ( _ : any ) => any ) : void {
@@ -279,7 +281,7 @@ export class NSLocationStrategy extends LocationStrategy {
279281 let result = [ ] ;
280282
281283 this . outlets . forEach ( outlet => {
282- const outletStates = outlet . statesByOutlet ;
284+ const outletStates = outlet . states ;
283285 const outletLog = outletStates
284286 // tslint:disable-next-line:max-line-length
285287 . map ( ( v , i ) => `${ outlet . outletKeys } .${ i } .[${ v . isPageNavigation ? "PAGE" : "INTERNAL" } ].[${ outlet . modalNavigationDepth ? "MODAL" : "BASE" } ] "${ v . segmentGroup . toString ( ) } "` )
@@ -336,9 +338,9 @@ export class NSLocationStrategy extends LocationStrategy {
336338 this . _modalNavigationDepth ++ ;
337339 }
338340
339- public _finishCloseModalNavigation ( ) {
341+ public _closeModalNavigation ( ) {
340342 if ( isLogEnabled ( ) ) {
341- routerLog ( "NSLocationStrategy.finishCloseModalNavigation ()" ) ;
343+ routerLog ( "NSLocationStrategy.closeModalNavigation ()" ) ;
342344 }
343345 this . _modalNavigationDepth -- ;
344346
@@ -365,7 +367,7 @@ export class NSLocationStrategy extends LocationStrategy {
365367 if ( isLogEnabled ( ) ) {
366368 routerLog ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
367369 }
368- this . currentOutlet . statesByOutlet = [ lastState ] ;
370+ this . currentOutlet . states = [ lastState ] ;
369371 }
370372
371373 this . _currentNavigationOptions = undefined ;
@@ -412,7 +414,13 @@ export class NSLocationStrategy extends LocationStrategy {
412414
413415 while ( segmentGroup ) {
414416 const url = segmentGroup . toString ( ) ;
415- fullPath = fullPath ? ( url ? url + "/" : url ) + fullPath : url ;
417+
418+ if ( fullPath ) {
419+ fullPath = ( url ? url + "/" : "" ) + fullPath ;
420+ } else {
421+ fullPath = url ;
422+ }
423+
416424 segmentGroup = segmentGroup . parent ;
417425 }
418426
@@ -496,9 +504,9 @@ export class NSLocationStrategy extends LocationStrategy {
496504 }
497505
498506 private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup ) : boolean {
499- const isNewPage = outlet . statesByOutlet . length === 0 ;
500- const lastState = outlet . statesByOutlet [ outlet . statesByOutlet . length - 1 ] ;
501- const equalStateUrls = outlet . containsLastState ( currentSegmentGroup . toString ( ) ) ;
507+ const isNewPage = outlet . states . length === 0 ;
508+ const lastState = outlet . states [ outlet . states . length - 1 ] ;
509+ const equalStateUrls = outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
502510
503511 const locationState : LocationState = {
504512 segmentGroup : currentSegmentGroup ,
@@ -507,7 +515,7 @@ export class NSLocationStrategy extends LocationStrategy {
507515 } ;
508516
509517 if ( ! lastState || ! equalStateUrls ) {
510- outlet . statesByOutlet . push ( locationState ) ;
518+ outlet . states . push ( locationState ) ;
511519
512520 if ( this . _modalNavigationDepth === 0 && ! outlet . showingModal ) {
513521 this . updateParentsStates ( outlet , currentSegmentGroup . parent ) ;
@@ -553,7 +561,7 @@ export class NSLocationStrategy extends LocationStrategy {
553561 isPageNavigation : true // It is a new OutletNode.
554562 } ;
555563
556- newOutlet . statesByOutlet = [ locationState ] ;
564+ newOutlet . states = [ locationState ] ;
557565 newOutlet . parent = parent ;
558566 this . outlets . push ( newOutlet ) ;
559567
@@ -571,6 +579,9 @@ export class NSLocationStrategy extends LocationStrategy {
571579 if ( childrenCount && segmentGroup . children [ currentPath ] ) {
572580 segmentGroup = segmentGroup . children [ currentPath ] ;
573581 } else {
582+ // If no child outlet found with the given name - forget about all previously found outlets.
583+ // example: seaching for 'primary-second-primary' shouldn't return 'primary-second'
584+ // if no 'primary' child available on 'second'.
574585 segmentGroup = null ;
575586 break ;
576587 }
@@ -580,10 +591,9 @@ export class NSLocationStrategy extends LocationStrategy {
580591 }
581592
582593 // Traversal and replacement of segmentGroup.
583- private updateSegmentGroup ( rootNode , oldSegmentGroup : UrlSegmentGroup , newSegmentGroup : UrlSegmentGroup ) {
594+ private updateSegmentGroup ( rootNode : any , oldSegmentGroup : UrlSegmentGroup , newSegmentGroup : UrlSegmentGroup ) {
584595 const queue = [ ] ;
585- queue . push ( rootNode ) ;
586- let currentTree = queue . shift ( ) ;
596+ let currentTree = rootNode ;
587597
588598 while ( currentTree ) {
589599 Object . keys ( currentTree . children ) . forEach ( outletName => {
0 commit comments