11import { Injectable } from "@angular/core" ;
22import { LocationStrategy } from "@angular/common" ;
3- import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot } from "@angular/router" ;
3+ import { DefaultUrlSerializer , UrlSegmentGroup , UrlTree , ActivatedRouteSnapshot , Params } from "@angular/router" ;
44import { routerLog , routerError , isLogEnabled } from "../trace" ;
55import { NavigationTransition , Frame } from "@nativescript/core/ui/frame" ;
66import { isPresent } from "../lang-facade" ;
@@ -85,6 +85,7 @@ const defaultNavOptions: NavigationOptions = {
8585} ;
8686
8787export interface LocationState {
88+ queryParams : Params ;
8889 segmentGroup : UrlSegmentGroup ;
8990 isRootSegmentGroup : boolean ;
9091 isPageNavigation : boolean ;
@@ -131,6 +132,7 @@ export class NSLocationStrategy extends LocationStrategy {
131132 }
132133
133134 const urlSerializer = new DefaultUrlSerializer ( ) ;
135+ tree . queryParams = state . queryParams ;
134136 const url = urlSerializer . serialize ( tree ) ;
135137 if ( isLogEnabled ( ) ) {
136138 routerLog ( "NSLocationStrategy.path(): " + url ) ;
@@ -165,10 +167,11 @@ export class NSLocationStrategy extends LocationStrategy {
165167 const outletKey = this . getOutletKey ( this . getSegmentGroupFullPath ( segmentGroup ) , "primary" ) ;
166168 const outlet = this . findOutlet ( outletKey ) ;
167169
168- if ( outlet && this . updateStates ( outlet , segmentGroup ) ) {
170+ if ( outlet && this . updateStates ( outlet , segmentGroup , this . currentUrlTree . queryParams ) ) {
169171 this . currentOutlet = outlet ; // If states updated
170172 } 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 ) ;
172175 this . currentOutlet = rootOutlet ;
173176 }
174177
@@ -197,15 +200,15 @@ export class NSLocationStrategy extends LocationStrategy {
197200 const containsLastState = outlet && outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
198201 if ( ! outlet ) {
199202 // 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 ) ;
201204 this . currentOutlet = outlet ;
202205 } else if ( this . _modalNavigationDepth > 0 && outlet . showingModal && ! containsLastState ) {
203206 // Navigation inside modal view.
204- this . upsertModalOutlet ( outlet , currentSegmentGroup ) ;
207+ this . upsertModalOutlet ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ;
205208 } else {
206209 outlet . parent = parentOutlet ;
207210
208- if ( this . updateStates ( outlet , currentSegmentGroup ) ) {
211+ if ( this . updateStates ( outlet , currentSegmentGroup , this . currentUrlTree . queryParams ) ) {
209212 this . currentOutlet = outlet ; // If states updated
210213 }
211214 }
@@ -604,15 +607,16 @@ export class NSLocationStrategy extends LocationStrategy {
604607 return outlet ;
605608 }
606609
607- private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup ) : boolean {
610+ private updateStates ( outlet : Outlet , currentSegmentGroup : UrlSegmentGroup , queryParams : Params ) : boolean {
608611 const isNewPage = outlet . states . length === 0 ;
609612 const lastState = outlet . states [ outlet . states . length - 1 ] ;
610613 const equalStateUrls = outlet . containsTopState ( currentSegmentGroup . toString ( ) ) ;
611614
612615 const locationState : LocationState = {
613616 segmentGroup : currentSegmentGroup ,
614617 isRootSegmentGroup : false ,
615- isPageNavigation : isNewPage
618+ isPageNavigation : isNewPage ,
619+ queryParams : { ...queryParams }
616620 } ;
617621
618622 if ( ! lastState || ! equalStateUrls ) {
@@ -645,14 +649,15 @@ export class NSLocationStrategy extends LocationStrategy {
645649 }
646650
647651 // 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 {
649653 const pathByOutlets = this . getPathByOutlets ( segmentGroup ) ;
650654 const newOutlet = new Outlet ( outletKey , path , pathByOutlets , modalNavigation ) ;
651655
652656 const locationState : LocationState = {
653657 segmentGroup : segmentGroup ,
654658 isRootSegmentGroup : false ,
655- isPageNavigation : true // It is a new OutletNode.
659+ isPageNavigation : true , // It is a new OutletNode.
660+ queryParams : { ...queryParams }
656661 } ;
657662
658663 newOutlet . states = [ locationState ] ;
@@ -719,7 +724,7 @@ export class NSLocationStrategy extends LocationStrategy {
719724 }
720725 }
721726
722- private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup ) {
727+ private upsertModalOutlet ( parentOutlet : Outlet , segmentedGroup : UrlSegmentGroup , queryParams : Params ) {
723728 let currentModalOutlet = this . findOutletByModal ( this . _modalNavigationDepth ) ;
724729
725730 // We want to treat every p-r-o as a standalone Outlet.
@@ -734,9 +739,9 @@ export class NSLocationStrategy extends LocationStrategy {
734739 const outletPath = parentOutlet . peekState ( ) . segmentGroup . toString ( ) ;
735740 const outletKey = this . getOutletKey ( outletPath , outletName ) ;
736741 // 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 ) ;
738743 this . currentOutlet = currentModalOutlet ;
739- } else if ( this . updateStates ( currentModalOutlet , segmentedGroup ) ) {
744+ } else if ( this . updateStates ( currentModalOutlet , segmentedGroup , queryParams ) ) {
740745 this . currentOutlet = currentModalOutlet ; // If states updated
741746 }
742747 }
0 commit comments