( oldRoot: UrlSegmentGroup, oldSegmentGroup: UrlSegmentGroup, newSegmentGroup: UrlSegmentGroup, queryParams: Params | null, fragment: string | null, urlSerializer: UrlSerializer, )
| 180 | } |
| 181 | |
| 182 | function tree( |
| 183 | oldRoot: UrlSegmentGroup, |
| 184 | oldSegmentGroup: UrlSegmentGroup, |
| 185 | newSegmentGroup: UrlSegmentGroup, |
| 186 | queryParams: Params | null, |
| 187 | fragment: string | null, |
| 188 | urlSerializer: UrlSerializer, |
| 189 | ): UrlTree { |
| 190 | const qp: Params = {}; |
| 191 | for (const [key, value] of Object.entries(queryParams ?? {})) { |
| 192 | // This retains old behavior where each item in the array was stringified individually This |
| 193 | // helps remove special-case handling for empty and single-item arrays where the default |
| 194 | // serializer removes empty arrays when serialized then parsed or converts them to non-arrays |
| 195 | // for single-item arrays. Changing this could have breaking change implications. Prior code |
| 196 | // always returned arrays of strings for array inputs so tests, applications, serializers, |
| 197 | // etc. may only be set up to handle string arrays. We could consider changing this in the |
| 198 | // future to serialize the entire array as a single value. For now, this feels safer and is |
| 199 | // at least a step in the right direction. |
| 200 | qp[key] = Array.isArray(value) |
| 201 | ? value.map((v) => normalizeQueryParams(key, v, urlSerializer)) |
| 202 | : normalizeQueryParams(key, value, urlSerializer); |
| 203 | } |
| 204 | |
| 205 | let rootCandidate: UrlSegmentGroup; |
| 206 | if (oldRoot === oldSegmentGroup) { |
| 207 | rootCandidate = newSegmentGroup; |
| 208 | } else { |
| 209 | rootCandidate = replaceSegment(oldRoot, oldSegmentGroup, newSegmentGroup); |
| 210 | } |
| 211 | |
| 212 | const newRoot = createRoot(squashSegmentGroup(rootCandidate)); |
| 213 | return new UrlTree(newRoot, qp, fragment); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Replaces the `oldSegment` which is located in some child of the `current` with the `newSegment`. |
no test coverage detected
searching dependent graphs…