1
1
import { Injectable } from "@angular/core" ;
2
2
import { LocationStrategy } from "@angular/common" ;
3
- import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot } from "@angular/router" ;
3
+ import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot , Params } from "@angular/router" ;
4
4
import { routerLog , routerError , isLogEnabled } from "../trace" ;
5
5
import { NavigationTransition , Frame } from "@nativescript/core/ui/frame" ;
6
6
import { isPresent } from "../lang-facade" ;
@@ -85,6 +85,7 @@ const defaultNavOptions: NavigationOptions = {
85
85
} ;
86
86
87
87
export interface LocationState {
88
+ queryParams : Params ;
88
89
segmentGroup : UrlSegmentGroup ;
89
90
isRootSegmentGroup : boolean ;
90
91
isPageNavigation : boolean ;
@@ -131,6 +132,7 @@ export class NSLocationStrategy extends LocationStrategy {
131
132
}
132
133
133
134
const urlSerializer = new DefaultUrlSerializer ( ) ;
135
+ tree . queryParams = state . queryParams ;
134
136
const url = urlSerializer . serialize ( tree ) ;
135
137
if ( isLogEnabled ( ) ) {
136
138
routerLog ( "NSLocationStrategy.path(): " + url ) ;
@@ -165,10 +167,11 @@ export class NSLocationStrategy extends LocationStrategy {
165
167
const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , "primary" ) ;
166
168
const outlet = this . findOutlet ( outletKey ) ;
167
169
168
- if ( outlet && this . updateStates ( outlet , segmentGroup ) ) {
170
+ if ( outlet && this . updateStates ( outlet , segmentGroup , this . currentUrlTree . queryParams ) ) {
169
171
this . currentOutlet = outlet ; // If states updated
170
172
} else if ( ! outlet ) {
171
- const rootOutlet = this . createOutlet ( "primary" , null , segmentGroup , null ) ;
173
+ // tslint:disable-next-line:max-line-length
174
+ const rootOutlet = this . createOutlet ( "primary" , null , segmentGroup , null , null , this . currentUrlTree . queryParams ) ;
172
175
this . currentOutlet = rootOutlet ;
173
176
}
174
177
@@ -197,15 +200,15 @@ export class NSLocationStrategy extends LocationStrategy {
197
200
const containsLastState = outlet && outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
198
201
if ( ! outlet ) {
199
202
// tslint:disable-next-line:max-line-length
200
- outlet = this . createOutlet ( outletKey , outletPath , currentSegmentGroup , parentOutlet , this . _modalNavigationDepth ) ;
203
+ outlet = this . createOutlet ( outletKey , outletPath , currentSegmentGroup , parentOutlet , this . _modalNavigationDepth , this . currentUrlTree . queryParams ) ;
201
204
this . currentOutlet = outlet ;
202
205
} else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
203
206
// Navigation inside modal view.
204
- this . upsertModalOutlet ( outlet , currentSegmentGroup ) ;
207
+ this . upsertModalOutlet ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ;
205
208
} else {
206
209
outlet . parent = parentOutlet ;
207
210
208
- if ( this . updateStates ( outlet , currentSegmentGroup ) ) {
211
+ if ( this . updateStates ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ) {
209
212
this . currentOutlet = outlet ; // If states updated
210
213
}
211
214
}
@@ -604,15 +607,16 @@ export class NSLocationStrategy extends LocationStrategy {
604
607
return outlet ;
605
608
}
606
609
607
- private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup ) : boolean {
610
+ private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup , queryParams : Params ) : boolean {
608
611
const isNewPage = outlet . states . length === 0 ;
609
612
const lastState = outlet . states [ outlet . states . length - 1 ] ;
610
613
const equalStateUrls = outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
611
614
612
615
const locationState : LocationState = {
613
616
segmentGroup : currentSegmentGroup ,
614
617
isRootSegmentGroup : false ,
615
- isPageNavigation : isNewPage
618
+ isPageNavigation : isNewPage ,
619
+ queryParams : { ...queryParams }
616
620
} ;
617
621
618
622
if ( ! lastState || ! equalStateUrls ) {
@@ -645,14 +649,15 @@ export class NSLocationStrategy extends LocationStrategy {
645
649
}
646
650
647
651
// tslint:disable-next-line:max-line-length
648
- private createOutlet ( outletKey : string , path : string , segmentGroup : any , parent : Outlet , modalNavigation ?: number ) : Outlet {
652
+ private createOutlet ( outletKey : string , path : string , segmentGroup : any , parent : Outlet , modalNavigation ?: number , queryParams : Params = { } ) : Outlet {
649
653
const pathByOutlets = this . getPathByOutlets ( segmentGroup ) ;
650
654
const newOutlet = new Outlet ( outletKey , path , pathByOutlets , modalNavigation ) ;
651
655
652
656
const locationState : LocationState = {
653
657
segmentGroup : segmentGroup ,
654
658
isRootSegmentGroup : false ,
655
- isPageNavigation : true // It is a new OutletNode.
659
+ isPageNavigation : true , // It is a new OutletNode.
660
+ queryParams : { ...queryParams }
656
661
} ;
657
662
658
663
newOutlet . states = [ locationState ] ;
@@ -719,7 +724,7 @@ export class NSLocationStrategy extends LocationStrategy {
719
724
}
720
725
}
721
726
722
- private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup ) {
727
+ private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup , queryParams : Params ) {
723
728
let currentModalOutlet = this . findOutletByModal ( this . _modalNavigationDepth ) ;
724
729
725
730
// We want to treat every p-r-o as a standalone Outlet.
@@ -734,9 +739,9 @@ export class NSLocationStrategy extends LocationStrategy {
734
739
const outletPath = parentOutlet . peekState ( ) . segmentGroup . toString ( ) ;
735
740
const outletKey = this . getOutletKey ( outletPath , outletName ) ;
736
741
// tslint:disable-next-line:max-line-length
737
- currentModalOutlet = this . createOutlet ( outletKey , outletPath , segmentedGroup , parentOutlet , this . _modalNavigationDepth ) ;
742
+ currentModalOutlet = this . createOutlet ( outletKey , outletPath , segmentedGroup , parentOutlet , this . _modalNavigationDepth , queryParams ) ;
738
743
this . currentOutlet = currentModalOutlet ;
739
- } else if ( this . updateStates ( currentModalOutlet , segmentedGroup ) ) {
744
+ } else if ( this . updateStates ( currentModalOutlet , segmentedGroup , queryParams ) ) {
740
745
this . currentOutlet = currentModalOutlet ; // If states updated
741
746
}
742
747
}
0 commit comments