@@ -15,18 +15,24 @@ export class Outlet {
15
15
// More than one key available when using NSEmptyOutletComponent component
16
16
// in module that lazy loads children (loadChildren) and has outlet name.
17
17
outletKeys : Array < string > ;
18
+
19
+ // The url path to the Outlet.
20
+ // E.G: the path to Outlet3 that is nested Outlet1(home)->Outlet2(nested1)->Outlet3(nested2)
21
+ // will be 'home/nested1'
22
+ path : string ;
18
23
pathByOutlets : string ;
19
24
states : Array < LocationState > = [ ] ;
20
25
frame : Frame ;
21
26
22
27
// Used in reuse-strategy by its children to determine if they should be detached too.
23
28
shouldDetach : boolean = true ;
24
- constructor ( outletKey : string , pathByOutlets : string , modalNavigationDepth ?: number ) {
29
+ constructor ( outletKey : string , path : string , pathByOutlets : string , modalNavigationDepth ?: number ) {
25
30
this . outletKeys = [ outletKey ] ;
26
31
this . isPageNavigationBack = false ;
27
32
this . showingModal = false ;
28
33
this . modalNavigationDepth = modalNavigationDepth || 0 ;
29
34
this . pathByOutlets = pathByOutlets ;
35
+ this . path = path ;
30
36
}
31
37
32
38
peekState ( ) : LocationState {
@@ -88,7 +94,7 @@ export class NSLocationStrategy extends LocationStrategy {
88
94
}
89
95
90
96
let tree = this . currentUrlTree ;
91
- let changedOutlet = this . getSegmentGroup ( this . currentOutlet . pathByOutlets ) ;
97
+ let changedOutlet = this . getSegmentGroupByOutlet ( this . currentOutlet ) ;
92
98
93
99
// Handle case where the user declares a component at path "/".
94
100
// The url serializer doesn't parse this url as having a primary outlet.
@@ -130,13 +136,13 @@ export class NSLocationStrategy extends LocationStrategy {
130
136
// The url serializer doesn't parse this url as having a primary outlet.
131
137
if ( ! Object . keys ( urlTreeRoot . children ) . length ) {
132
138
const segmentGroup = this . currentUrlTree && this . currentUrlTree . root ;
133
- const outletKey = this . getSegmentGroupFullPath ( segmentGroup ) + "primary" ;
139
+ const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , "primary" ) ;
134
140
const outlet = this . findOutletByKey ( outletKey ) ;
135
141
136
142
if ( outlet && this . updateStates ( outlet , segmentGroup ) ) {
137
143
this . currentOutlet = outlet ; // If states updated
138
144
} else if ( ! outlet ) {
139
- const rootOutlet = this . createOutlet ( "primary" , segmentGroup , null ) ;
145
+ const rootOutlet = this . createOutlet ( "primary" , null , segmentGroup , null ) ;
140
146
this . currentOutlet = rootOutlet ;
141
147
}
142
148
@@ -153,16 +159,19 @@ export class NSLocationStrategy extends LocationStrategy {
153
159
currentSegmentGroup . outlet = outletName ;
154
160
currentSegmentGroup . root = urlTreeRoot ;
155
161
156
- let outletKey = this . getSegmentGroupFullPath ( currentTree ) + outletName ;
162
+ const outletPath = this . getSegmentGroupFullPath ( currentTree ) ;
163
+ let outletKey = this . getOutletKey ( outletPath , outletName ) ;
157
164
let outlet = this . findOutletByKey ( outletKey ) ;
165
+
158
166
const parentOutletName = currentTree . outlet || "" ;
159
- const parentOutletKey = this . getSegmentGroupFullPath ( currentTree . parent ) + parentOutletName ;
167
+ const parentOutletPath = this . getSegmentGroupFullPath ( currentTree . parent ) ;
168
+ const parentOutletKey = this . getOutletKey ( parentOutletPath , parentOutletName ) ;
160
169
const parentOutlet = this . findOutletByKey ( parentOutletKey ) ;
161
170
162
171
const containsLastState = outlet && outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
163
172
if ( ! outlet ) {
164
173
// tslint:disable-next-line:max-line-length
165
- outlet = this . createOutlet ( outletKey , currentSegmentGroup , parentOutlet , this . _modalNavigationDepth ) ;
174
+ outlet = this . createOutlet ( outletKey , outletPath , currentSegmentGroup , parentOutlet , this . _modalNavigationDepth ) ;
166
175
this . currentOutlet = outlet ;
167
176
} else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
168
177
// Navigation inside modal view.
@@ -270,7 +279,7 @@ export class NSLocationStrategy extends LocationStrategy {
270
279
private callPopState ( state : LocationState , pop : boolean = true , outlet ?: Outlet ) {
271
280
outlet = outlet || this . currentOutlet ;
272
281
const urlSerializer = new DefaultUrlSerializer ( ) ;
273
- let changedOutlet = this . getSegmentGroup ( outlet . pathByOutlets ) ;
282
+ let changedOutlet = this . getSegmentGroupByOutlet ( outlet ) ;
274
283
275
284
if ( state && changedOutlet ) {
276
285
this . updateSegmentGroup ( this . currentUrlTree . root , changedOutlet , state . segmentGroup ) ;
@@ -469,7 +478,7 @@ export class NSLocationStrategy extends LocationStrategy {
469
478
currentRoute = currentRoute . parent ;
470
479
}
471
480
472
- return fullPath ? fullPath + outletName : outletName ;
481
+ return fullPath ? fullPath + "-" + outletName : outletName ;
473
482
}
474
483
475
484
@@ -568,9 +577,10 @@ export class NSLocationStrategy extends LocationStrategy {
568
577
}
569
578
}
570
579
571
- private createOutlet ( outletKey : string , segmentGroup : any , parent : Outlet , modalNavigation ?: number ) : Outlet {
580
+ // tslint:disable-next-line:max-line-length
581
+ private createOutlet ( outletKey : string , path : string , segmentGroup : any , parent : Outlet , modalNavigation ?: number ) : Outlet {
572
582
const pathByOutlets = this . getPathByOutlets ( segmentGroup ) ;
573
- const newOutlet = new Outlet ( outletKey , pathByOutlets , modalNavigation ) ;
583
+ const newOutlet = new Outlet ( outletKey , path , pathByOutlets , modalNavigation ) ;
574
584
575
585
const locationState : LocationState = {
576
586
segmentGroup : segmentGroup ,
@@ -590,15 +600,18 @@ export class NSLocationStrategy extends LocationStrategy {
590
600
return newOutlet ;
591
601
}
592
602
593
- private getSegmentGroup ( pathByOutlets : string ) : UrlSegmentGroup {
594
- const pathList = pathByOutlets . split ( "-" ) ;
603
+ private getSegmentGroupByOutlet ( outlet : Outlet ) : UrlSegmentGroup {
604
+ const pathList = outlet . pathByOutlets . split ( "-" ) ;
595
605
let segmentGroup = this . currentUrlTree . root ;
606
+ let pathToOutlet ;
596
607
597
608
for ( let index = 0 ; index < pathList . length ; index ++ ) {
598
609
const currentPath = pathList [ index ] ;
599
610
const childrenCount = Object . keys ( segmentGroup . children ) . length ;
600
611
601
612
if ( childrenCount && segmentGroup . children [ currentPath ] ) {
613
+ const url = segmentGroup . toString ( ) ;
614
+ pathToOutlet = pathToOutlet ? pathToOutlet + "/" + url : url ;
602
615
segmentGroup = segmentGroup . children [ currentPath ] ;
603
616
} else {
604
617
// If no child outlet found with the given name - forget about all previously found outlets.
@@ -609,6 +622,12 @@ export class NSLocationStrategy extends LocationStrategy {
609
622
}
610
623
}
611
624
625
+ // Paths should also match since there could be another Outlet
626
+ // with the same pathByOutlets but different url path.
627
+ if ( segmentGroup && outlet . path && pathToOutlet && outlet . path !== pathToOutlet ) {
628
+ segmentGroup = null ;
629
+ }
630
+
612
631
return segmentGroup ;
613
632
}
614
633
@@ -645,11 +664,17 @@ export class NSLocationStrategy extends LocationStrategy {
645
664
646
665
// No currentModalOutlet available when opening 'primary' p-r-o.
647
666
const outletName = "primary" ;
648
- const outletKey = parentOutlet . peekState ( ) . segmentGroup . toString ( ) + outletName ;
649
- currentModalOutlet = this . createOutlet ( outletKey , segmentedGroup , parentOutlet , this . _modalNavigationDepth ) ;
667
+ const outletPath = parentOutlet . peekState ( ) . segmentGroup . toString ( ) ;
668
+ const outletKey = this . getOutletKey ( outletPath , outletName ) ;
669
+ // tslint:disable-next-line:max-line-length
670
+ currentModalOutlet = this . createOutlet ( outletKey , outletPath , segmentedGroup , parentOutlet , this . _modalNavigationDepth ) ;
650
671
this . currentOutlet = currentModalOutlet ;
651
672
} else if ( this . updateStates ( currentModalOutlet , segmentedGroup ) ) {
652
673
this . currentOutlet = currentModalOutlet ; // If states updated
653
674
}
654
675
}
676
+
677
+ private getOutletKey ( path : string , outletName : string ) : string {
678
+ return path ? path + "-" + outletName : outletName ;
679
+ }
655
680
}
0 commit comments