@@ -11,15 +11,7 @@ import {ɵRuntimeError as RuntimeError} from '@angular/core';
1111import { RuntimeErrorCode } from './errors' ;
1212import { ActivatedRouteSnapshot } from './router_state' ;
1313import { Params , PRIMARY_OUTLET } from './shared' ;
14- import {
15- createRoot ,
16- DefaultUrlSerializer ,
17- squashSegmentGroup ,
18- UrlSegment ,
19- UrlSegmentGroup ,
20- UrlSerializer ,
21- UrlTree ,
22- } from './url_tree' ;
14+ import { createRoot , squashSegmentGroup , UrlSegment , UrlSegmentGroup , UrlTree } from './url_tree' ;
2315import { last , shallowEqual } from './utils/collection' ;
2416
2517/**
@@ -36,9 +28,6 @@ import {last, shallowEqual} from './utils/collection';
3628 * @param queryParams The query parameters for the `UrlTree`. `null` if the `UrlTree` does not have
3729 * any query parameters.
3830 * @param fragment The fragment for the `UrlTree`. `null` if the `UrlTree` does not have a fragment.
39- * @param urlSerializer The `UrlSerializer` to use for handling query parameter normalization.
40- * You should provide your application's custom `UrlSerializer` if one is configured to parse and
41- * serialize query parameter values to and from objects other than strings/string arrays.
4231 *
4332 * @usageNotes
4433 *
@@ -81,16 +70,9 @@ export function createUrlTreeFromSnapshot(
8170 commands : readonly any [ ] ,
8271 queryParams : Params | null = null ,
8372 fragment : string | null = null ,
84- urlSerializer = new DefaultUrlSerializer ( ) ,
8573) : UrlTree {
8674 const relativeToUrlSegmentGroup = createSegmentGroupFromRoute ( relativeTo ) ;
87- return createUrlTreeFromSegmentGroup (
88- relativeToUrlSegmentGroup ,
89- commands ,
90- queryParams ,
91- fragment ,
92- urlSerializer ,
93- ) ;
75+ return createUrlTreeFromSegmentGroup ( relativeToUrlSegmentGroup , commands , queryParams , fragment ) ;
9476}
9577
9678export function createSegmentGroupFromRoute ( route : ActivatedRouteSnapshot ) : UrlSegmentGroup {
@@ -121,7 +103,6 @@ export function createUrlTreeFromSegmentGroup(
121103 commands : readonly any [ ] ,
122104 queryParams : Params | null ,
123105 fragment : string | null ,
124- urlSerializer : UrlSerializer ,
125106) : UrlTree {
126107 let root = relativeTo ;
127108 while ( root . parent ) {
@@ -131,20 +112,20 @@ export function createUrlTreeFromSegmentGroup(
131112 // `UrlSegmentGroup`. All we need to do is update the `queryParams` and `fragment` without
132113 // applying any other logic.
133114 if ( commands . length === 0 ) {
134- return tree ( root , root , root , queryParams , fragment , urlSerializer ) ;
115+ return tree ( root , root , root , queryParams , fragment ) ;
135116 }
136117
137118 const nav = computeNavigation ( commands ) ;
138119
139120 if ( nav . toRoot ( ) ) {
140- return tree ( root , root , new UrlSegmentGroup ( [ ] , { } ) , queryParams , fragment , urlSerializer ) ;
121+ return tree ( root , root , new UrlSegmentGroup ( [ ] , { } ) , queryParams , fragment ) ;
141122 }
142123
143124 const position = findStartingPositionForTargetGroup ( nav , root , relativeTo ) ;
144125 const newSegmentGroup = position . processChildren
145126 ? updateSegmentGroupChildren ( position . segmentGroup , position . index , nav . commands )
146127 : updateSegmentGroup ( position . segmentGroup , position . index , nav . commands ) ;
147- return tree ( root , position . segmentGroup , newSegmentGroup , queryParams , fragment , urlSerializer ) ;
128+ return tree ( root , position . segmentGroup , newSegmentGroup , queryParams , fragment ) ;
148129}
149130
150131function isMatrixParams ( command : any ) : boolean {
@@ -159,43 +140,18 @@ function isCommandWithOutlets(command: any): command is {outlets: {[key: string]
159140 return typeof command === 'object' && command != null && command . outlets ;
160141}
161142
162- /**
163- * Normalizes a query parameter value by using the `UrlSerializer` to serialize then parse the value.
164- *
165- * This ensures that the value is consistent between parsing a URL in the browser on a fresh page load (or page refresh)
166- * and a navigation where the query parameter value is passed directly to the router.
167- *
168- * This also allows custom `UrlSerializer` implementations to define how query parameter values are represented
169- * in a `UrlTree`. Since `UrlSerializer` already has a `parse` that takes a string, it already has control
170- * over how a browser URL is parsed into a `UrlTree` on initial load/page refresh.
171- */
172- function normalizeQueryParams ( k : string , v : unknown , urlSerializer : UrlSerializer ) : unknown {
173- const tree = new UrlTree ( ) ;
174- tree . queryParams = { [ k ] : v } ;
175- return urlSerializer . parse ( urlSerializer . serialize ( tree ) ) . queryParams [ k ] ;
176- }
177-
178143function tree (
179144 oldRoot : UrlSegmentGroup ,
180145 oldSegmentGroup : UrlSegmentGroup ,
181146 newSegmentGroup : UrlSegmentGroup ,
182147 queryParams : Params | null ,
183148 fragment : string | null ,
184- urlSerializer : UrlSerializer ,
185149) : UrlTree {
186- const qp : Params = { } ;
187- for ( const [ key , value ] of Object . entries ( queryParams ?? { } ) ) {
188- // This retains old behavior where each item in the array was stringified individually This
189- // helps remove special-case handling for empty and single-item arrays where the default
190- // serializer removes empty arrays when serialized then parsed or converts them to non-arrays
191- // for single-item arrays. Changing this could have breaking change implications. Prior code
192- // always returned arrays of strings for array inputs so tests, applications, serializers,
193- // etc. may only be set up to handle string arrays. We could consider changing this in the
194- // future to serialize the entire array as a single value. For now, this feels safer and is
195- // at least a step in the right direction.
196- qp [ key ] = Array . isArray ( value )
197- ? value . map ( ( v ) => normalizeQueryParams ( key , v , urlSerializer ) )
198- : normalizeQueryParams ( key , value , urlSerializer ) ;
150+ let qp : any = { } ;
151+ if ( queryParams ) {
152+ Object . entries ( queryParams ) . forEach ( ( [ name , value ] ) => {
153+ qp [ name ] = Array . isArray ( value ) ? value . map ( ( v : any ) => `${ v } ` ) : `${ value } ` ;
154+ } ) ;
199155 }
200156
201157 let rootCandidate : UrlSegmentGroup ;
0 commit comments