@@ -72,7 +72,7 @@ export class NSLocationStrategy extends LocationStrategy {
72
72
this . pushStateInternal ( state , title , url , queryParams ) ;
73
73
}
74
74
75
- pushStateInternal ( state : any , title : string , url : string , queryParams : string ) : void {
75
+ pushStateInternal ( state : any , title : string , url : string , queryParams : string , replace = false ) : void {
76
76
const urlSerializer = new DefaultUrlSerializer ( ) ;
77
77
this . currentUrlTree = urlSerializer . parse ( url ) ;
78
78
const urlTreeRoot = this . currentUrlTree . root ;
@@ -84,7 +84,7 @@ export class NSLocationStrategy extends LocationStrategy {
84
84
const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , 'primary' ) ;
85
85
const outlet = this . findOutlet ( outletKey ) ;
86
86
87
- if ( outlet && this . updateStates ( outlet , segmentGroup , this . currentUrlTree . queryParams ) ) {
87
+ if ( outlet && this . updateStates ( outlet , segmentGroup , this . currentUrlTree . queryParams , replace ) ) {
88
88
this . currentOutlet = outlet ; // If states updated
89
89
} else if ( ! outlet ) {
90
90
// tslint:disable-next-line:max-line-length
@@ -121,11 +121,11 @@ export class NSLocationStrategy extends LocationStrategy {
121
121
this . currentOutlet = outlet ;
122
122
} else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
123
123
// Navigation inside modal view.
124
- this . upsertModalOutlet ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ;
124
+ this . upsertModalOutlet ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams , replace ) ;
125
125
} else {
126
126
outlet . parent = parentOutlet ;
127
127
128
- if ( this . updateStates ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ) {
128
+ if ( this . updateStates ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams , replace ) ) {
129
129
this . currentOutlet = outlet ; // If states updated
130
130
}
131
131
}
@@ -144,6 +144,7 @@ export class NSLocationStrategy extends LocationStrategy {
144
144
if ( NativeScriptDebug . isLogEnabled ( ) ) {
145
145
NativeScriptDebug . routerLog ( 'NSLocationStrategy.replaceState changing existing state: ' + `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
146
146
}
147
+ this . pushStateInternal ( state , title , url , queryParams , true ) ;
147
148
} else {
148
149
if ( NativeScriptDebug . isLogEnabled ( ) ) {
149
150
NativeScriptDebug . routerLog ( 'NSLocationStrategy.replaceState pushing new state: ' + `${ state } , title: ${ title } , url: ${ url } , queryParams: ${ queryParams } ` ) ;
@@ -381,6 +382,7 @@ export class NSLocationStrategy extends LocationStrategy {
381
382
clearHistory : isPresent ( options . clearHistory ) ? options . clearHistory : false ,
382
383
animated : isPresent ( options . animated ) ? options . animated : true ,
383
384
transition : options . transition ,
385
+ replaceUrl : options . replaceUrl ,
384
386
} ;
385
387
386
388
if ( NativeScriptDebug . isLogEnabled ( ) ) {
@@ -532,7 +534,7 @@ export class NSLocationStrategy extends LocationStrategy {
532
534
return outlet ;
533
535
}
534
536
535
- private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup , queryParams : Params ) : boolean {
537
+ private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup , queryParams : Params , replace = false ) : boolean {
536
538
const isNewPage = outlet . states . length === 0 ;
537
539
const lastState = outlet . states [ outlet . states . length - 1 ] ;
538
540
const equalStateUrls = outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
@@ -545,6 +547,9 @@ export class NSLocationStrategy extends LocationStrategy {
545
547
} ;
546
548
547
549
if ( ! lastState || ! equalStateUrls ) {
550
+ if ( replace ) {
551
+ outlet . states . pop ( ) ;
552
+ }
548
553
outlet . states . push ( locationState ) ;
549
554
550
555
// Update last state segmentGroup of parent Outlet.
@@ -553,6 +558,11 @@ export class NSLocationStrategy extends LocationStrategy {
553
558
}
554
559
555
560
return true ;
561
+ } else {
562
+ if ( lastState && equalStateUrls ) {
563
+ // update query params for last state
564
+ lastState . queryParams = { ...queryParams } ;
565
+ }
556
566
}
557
567
558
568
return false ;
@@ -649,7 +659,7 @@ export class NSLocationStrategy extends LocationStrategy {
649
659
}
650
660
}
651
661
652
- private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup , queryParams : Params ) {
662
+ private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup , queryParams : Params , replace = false ) {
653
663
let currentModalOutlet = this . findOutletByModal ( this . _modalNavigationDepth ) ;
654
664
655
665
// We want to treat every p-r-o as a standalone Outlet.
@@ -666,7 +676,7 @@ export class NSLocationStrategy extends LocationStrategy {
666
676
// tslint:disable-next-line:max-line-length
667
677
currentModalOutlet = this . createOutlet ( outletKey , outletPath , segmentedGroup , parentOutlet , this . _modalNavigationDepth , queryParams ) ;
668
678
this . currentOutlet = currentModalOutlet ;
669
- } else if ( this . updateStates ( currentModalOutlet , segmentedGroup , queryParams ) ) {
679
+ } else if ( this . updateStates ( currentModalOutlet , segmentedGroup , queryParams , replace ) ) {
670
680
this . currentOutlet = currentModalOutlet ; // If states updated
671
681
}
672
682
}
0 commit comments