@@ -72,7 +72,7 @@ export class NSLocationStrategy extends LocationStrategy {
7272 this . pushStateInternal ( state , title , url , queryParams ) ;
7373 }
7474
75- pushStateInternal ( state : any , title : string , url : string , queryParams : string ) : void {
75+ pushStateInternal ( state : any , title : string , url : string , queryParams : string , replace = false ) : void {
7676 const urlSerializer = new DefaultUrlSerializer ( ) ;
7777 this . currentUrlTree = urlSerializer . parse ( url ) ;
7878 const urlTreeRoot = this . currentUrlTree . root ;
@@ -84,7 +84,7 @@ export class NSLocationStrategy extends LocationStrategy {
8484 const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , 'primary' ) ;
8585 const outlet = this . findOutlet ( outletKey ) ;
8686
87- if ( outlet && this . updateStates ( outlet , segmentGroup , this . currentUrlTree . queryParams ) ) {
87+ if ( outlet && this . updateStates ( outlet , segmentGroup , this . currentUrlTree . queryParams , replace ) ) {
8888 this . currentOutlet = outlet ; // If states updated
8989 } else if ( ! outlet ) {
9090 // tslint:disable-next-line:max-line-length
@@ -121,11 +121,11 @@ export class NSLocationStrategy extends LocationStrategy {
121121 this . currentOutlet = outlet ;
122122 } else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
123123 // Navigation inside modal view.
124- this . upsertModalOutlet ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ;
124+ this . upsertModalOutlet ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams , replace ) ;
125125 } else {
126126 outlet . parent = parentOutlet ;
127127
128- if ( this . updateStates ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ) {
128+ if ( this . updateStates ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams , replace ) ) {
129129 this . currentOutlet = outlet ; // If states updated
130130 }
131131 }
@@ -144,6 +144,7 @@ export class NSLocationStrategy extends LocationStrategy {
144144 if ( NativeScriptDebug . isLogEnabled ( ) ) {
145145 NativeScriptDebug . routerLog ( 'NSLocationStrategy.replaceState changing existing state: ' + `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
146146 }
147+ this . pushStateInternal ( state , title , url , queryParams , true ) ;
147148 } else {
148149 if ( NativeScriptDebug . isLogEnabled ( ) ) {
149150 NativeScriptDebug . routerLog ( 'NSLocationStrategy.replaceState pushing new state: ' + `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
@@ -381,6 +382,7 @@ export class NSLocationStrategy extends LocationStrategy {
381382 clearHistory : isPresent ( options . clearHistory ) ? options . clearHistory : false ,
382383 animated : isPresent ( options . animated ) ? options . animated : true ,
383384 transition : options . transition ,
385+ replaceUrl : options . replaceUrl ,
384386 } ;
385387
386388 if ( NativeScriptDebug . isLogEnabled ( ) ) {
@@ -532,7 +534,7 @@ export class NSLocationStrategy extends LocationStrategy {
532534 return outlet ;
533535 }
534536
535- private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup , queryParams : Params ) : boolean {
537+ private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup , queryParams : Params , replace = false ) : boolean {
536538 const isNewPage = outlet . states . length === 0 ;
537539 const lastState = outlet . states [ outlet . states . length - 1 ] ;
538540 const equalStateUrls = outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
@@ -545,6 +547,9 @@ export class NSLocationStrategy extends LocationStrategy {
545547 } ;
546548
547549 if ( ! lastState || ! equalStateUrls ) {
550+ if ( replace ) {
551+ outlet . states . pop ( ) ;
552+ }
548553 outlet . states . push ( locationState ) ;
549554
550555 // Update last state segmentGroup of parent Outlet.
@@ -553,6 +558,11 @@ export class NSLocationStrategy extends LocationStrategy {
553558 }
554559
555560 return true ;
561+ } else {
562+ if ( lastState && equalStateUrls ) {
563+ // update query params for last state
564+ lastState . queryParams = { ...queryParams } ;
565+ }
556566 }
557567
558568 return false ;
@@ -649,7 +659,7 @@ export class NSLocationStrategy extends LocationStrategy {
649659 }
650660 }
651661
652- private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup , queryParams : Params ) {
662+ private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup , queryParams : Params , replace = false ) {
653663 let currentModalOutlet = this . findOutletByModal ( this . _modalNavigationDepth ) ;
654664
655665 // We want to treat every p-r-o as a standalone Outlet.
@@ -666,7 +676,7 @@ export class NSLocationStrategy extends LocationStrategy {
666676 // tslint:disable-next-line:max-line-length
667677 currentModalOutlet = this . createOutlet ( outletKey , outletPath , segmentedGroup , parentOutlet , this . _modalNavigationDepth , queryParams ) ;
668678 this . currentOutlet = currentModalOutlet ;
669- } else if ( this . updateStates ( currentModalOutlet , segmentedGroup , queryParams ) ) {
679+ } else if ( this . updateStates ( currentModalOutlet , segmentedGroup , queryParams , replace ) ) {
670680 this . currentOutlet = currentModalOutlet ; // If states updated
671681 }
672682 }
0 commit comments