@@ -11,9 +11,12 @@ export class Outlet {
11
11
modalNavigationDepth : number ;
12
12
parent : Outlet ;
13
13
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.
14
17
outletKeys : Array < string > ;
15
18
pathByOutlets : string ;
16
- statesByOutlet : Array < LocationState > = [ ] ;
19
+ states : Array < LocationState > = [ ] ;
17
20
frame : Frame ;
18
21
19
22
// Used in reuse-strategy by its children to determine if they should be detached too.
@@ -27,13 +30,13 @@ export class Outlet {
27
30
}
28
31
29
32
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 ] ;
32
35
}
33
36
return null ;
34
37
}
35
38
36
- containsLastState ( stateUrl : string ) : boolean {
39
+ containsTopState ( stateUrl : string ) : boolean {
37
40
const lastState = this . peekState ( ) ;
38
41
return lastState && lastState . segmentGroup . toString ( ) === stateUrl ;
39
42
}
@@ -92,7 +95,6 @@ export class NSLocationStrategy extends LocationStrategy {
92
95
if ( state . isRootSegmentGroup ) {
93
96
tree . root = state . segmentGroup ;
94
97
} else if ( changedOutlet ) {
95
- // tslint:disable-next-line:max-line-length
96
98
this . updateSegmentGroup ( tree . root , changedOutlet , state . segmentGroup ) ;
97
99
}
98
100
@@ -129,49 +131,49 @@ export class NSLocationStrategy extends LocationStrategy {
129
131
// The url serializer doesn't parse this url as having a primary outlet.
130
132
const rootOutlet = this . createOutlet ( "primary" , null , null ) ;
131
133
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 ) ;
159
151
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
163
165
}
166
+ }
164
167
165
- queue . push ( currentTree . children [ outletName ] ) ;
166
- } ) ;
168
+ queue . push ( currentSegmentGroup ) ;
169
+ } ) ;
167
170
168
- currentTree = queue . shift ( ) ;
169
- }
171
+ currentTree = queue . shift ( ) ;
170
172
}
171
173
}
172
174
173
175
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 ;
175
177
176
178
if ( states && states . length > 0 ) {
177
179
if ( isLogEnabled ( ) ) {
@@ -195,7 +197,7 @@ export class NSLocationStrategy extends LocationStrategy {
195
197
this . currentOutlet = outlet || this . currentOutlet ;
196
198
197
199
if ( this . currentOutlet . isPageNavigationBack ) {
198
- const states = this . currentOutlet . statesByOutlet ;
200
+ const states = this . currentOutlet . states ;
199
201
// We are navigating to the previous page
200
202
// clear the stack until we get to a page navigation state
201
203
let state = states . pop ( ) ;
@@ -231,14 +233,14 @@ export class NSLocationStrategy extends LocationStrategy {
231
233
" state is not page - just pop" ) ;
232
234
}
233
235
234
- this . callPopState ( this . currentOutlet . statesByOutlet . pop ( ) , true ) ;
236
+ this . callPopState ( this . currentOutlet . states . pop ( ) , true ) ;
235
237
}
236
238
}
237
239
}
238
240
239
241
canGoBack ( outlet ?: Outlet ) {
240
242
outlet = outlet || this . currentOutlet ;
241
- return outlet . statesByOutlet . length > 1 ;
243
+ return outlet . states . length > 1 ;
242
244
}
243
245
244
246
onPopState ( fn : ( _ : any ) => any ) : void {
@@ -279,7 +281,7 @@ export class NSLocationStrategy extends LocationStrategy {
279
281
let result = [ ] ;
280
282
281
283
this . outlets . forEach ( outlet => {
282
- const outletStates = outlet . statesByOutlet ;
284
+ const outletStates = outlet . states ;
283
285
const outletLog = outletStates
284
286
// tslint:disable-next-line:max-line-length
285
287
. 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 {
336
338
this . _modalNavigationDepth ++ ;
337
339
}
338
340
339
- public _finishCloseModalNavigation ( ) {
341
+ public _closeModalNavigation ( ) {
340
342
if ( isLogEnabled ( ) ) {
341
- routerLog ( "NSLocationStrategy.finishCloseModalNavigation ()" ) ;
343
+ routerLog ( "NSLocationStrategy.closeModalNavigation ()" ) ;
342
344
}
343
345
this . _modalNavigationDepth -- ;
344
346
@@ -365,7 +367,7 @@ export class NSLocationStrategy extends LocationStrategy {
365
367
if ( isLogEnabled ( ) ) {
366
368
routerLog ( "NSLocationStrategy._beginPageNavigation clearing states history" ) ;
367
369
}
368
- this . currentOutlet . statesByOutlet = [ lastState ] ;
370
+ this . currentOutlet . states = [ lastState ] ;
369
371
}
370
372
371
373
this . _currentNavigationOptions = undefined ;
@@ -412,7 +414,13 @@ export class NSLocationStrategy extends LocationStrategy {
412
414
413
415
while ( segmentGroup ) {
414
416
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
+
416
424
segmentGroup = segmentGroup . parent ;
417
425
}
418
426
@@ -496,9 +504,9 @@ export class NSLocationStrategy extends LocationStrategy {
496
504
}
497
505
498
506
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 ( ) ) ;
502
510
503
511
const locationState : LocationState = {
504
512
segmentGroup : currentSegmentGroup ,
@@ -507,7 +515,7 @@ export class NSLocationStrategy extends LocationStrategy {
507
515
} ;
508
516
509
517
if ( ! lastState || ! equalStateUrls ) {
510
- outlet . statesByOutlet . push ( locationState ) ;
518
+ outlet . states . push ( locationState ) ;
511
519
512
520
if ( this . _modalNavigationDepth === 0 && ! outlet . showingModal ) {
513
521
this . updateParentsStates ( outlet , currentSegmentGroup . parent ) ;
@@ -553,7 +561,7 @@ export class NSLocationStrategy extends LocationStrategy {
553
561
isPageNavigation : true // It is a new OutletNode.
554
562
} ;
555
563
556
- newOutlet . statesByOutlet = [ locationState ] ;
564
+ newOutlet . states = [ locationState ] ;
557
565
newOutlet . parent = parent ;
558
566
this . outlets . push ( newOutlet ) ;
559
567
@@ -571,6 +579,9 @@ export class NSLocationStrategy extends LocationStrategy {
571
579
if ( childrenCount && segmentGroup . children [ currentPath ] ) {
572
580
segmentGroup = segmentGroup . children [ currentPath ] ;
573
581
} 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'.
574
585
segmentGroup = null ;
575
586
break ;
576
587
}
@@ -580,10 +591,9 @@ export class NSLocationStrategy extends LocationStrategy {
580
591
}
581
592
582
593
// Traversal and replacement of segmentGroup.
583
- private updateSegmentGroup ( rootNode , oldSegmentGroup : UrlSegmentGroup , newSegmentGroup : UrlSegmentGroup ) {
594
+ private updateSegmentGroup ( rootNode : any , oldSegmentGroup : UrlSegmentGroup , newSegmentGroup : UrlSegmentGroup ) {
584
595
const queue = [ ] ;
585
- queue . push ( rootNode ) ;
586
- let currentTree = queue . shift ( ) ;
596
+ let currentTree = rootNode ;
587
597
588
598
while ( currentTree ) {
589
599
Object . keys ( currentTree . children ) . forEach ( outletName => {
0 commit comments