@@ -126,11 +126,21 @@ export class NSLocationStrategy extends LocationStrategy {
126126 this . currentUrlTree = urlSerializer . parse ( url ) ;
127127 const urlTreeRoot = this . currentUrlTree . root ;
128128
129+ // Handle case where the user declares a component at path "/".
130+ // The url serializer doesn't parse this url as having a primary outlet.
129131 if ( ! Object . keys ( urlTreeRoot . children ) . length ) {
130- // Handle case where the user declares a component at path "/".
131- // The url serializer doesn't parse this url as having a primary outlet.
132- const rootOutlet = this . createOutlet ( "primary" , null , null ) ;
133- this . currentOutlet = rootOutlet ;
132+ const segmentGroup = this . currentUrlTree && this . currentUrlTree . root ;
133+ const outletKey = this . getSegmentGroupFullPath ( segmentGroup ) + "primary" ;
134+ const outlet = this . findOutletByKey ( outletKey ) ;
135+
136+ if ( outlet && this . updateStates ( outlet , segmentGroup ) ) {
137+ this . currentOutlet = outlet ; // If states updated
138+ } else if ( ! outlet ) {
139+ const rootOutlet = this . createOutlet ( "primary" , segmentGroup , null ) ;
140+ this . currentOutlet = rootOutlet ;
141+ }
142+
143+ this . currentOutlet . peekState ( ) . isRootSegmentGroup = true ;
134144 return ;
135145 }
136146
@@ -543,27 +553,25 @@ export class NSLocationStrategy extends LocationStrategy {
543553 }
544554
545555 private createOutlet ( outletKey : string , segmentGroup : any , parent : Outlet , modalNavigation ?: number ) : Outlet {
546- let isRootSegmentGroup : boolean = false ;
547-
548- if ( ! segmentGroup ) {
549- // Handle case where the user declares a component at path "/".
550- // The url serializer doesn't parse this url as having a primary outlet.
551- segmentGroup = this . currentUrlTree && this . currentUrlTree . root ;
552- isRootSegmentGroup = true ;
553- }
554-
555556 const pathByOutlets = this . getPathByOutlets ( segmentGroup ) ;
556557 const newOutlet = new Outlet ( outletKey , pathByOutlets , modalNavigation ) ;
557558
558559 const locationState : LocationState = {
559560 segmentGroup : segmentGroup ,
560- isRootSegmentGroup : isRootSegmentGroup ,
561+ isRootSegmentGroup : false ,
561562 isPageNavigation : true // It is a new OutletNode.
562563 } ;
563564
564565 newOutlet . states = [ locationState ] ;
565566 newOutlet . parent = parent ;
566- this . outlets . push ( newOutlet ) ;
567+
568+ if ( isRootSegmentGroup && this . outlets . length ) {
569+ // Handle case where the user declares a component at path "/".
570+ // The url serializer doesn't parse this url as having a primary outlet.
571+ this . outlets [ 0 ] . states = newOutlet . states ;
572+ } else {
573+ this . outlets . push ( newOutlet ) ;
574+ }
567575
568576 return newOutlet ;
569577 }
0 commit comments