* Normalizes a query parameter value by using the `UrlSerializer` to serialize then parse the value. * * This ensures that the value is consistent between parsing a URL in the browser on a fresh page load (or page refresh) * and a navigation where the query parameter value is passed directly to t
(k: string, v: unknown, urlSerializer: UrlSerializer)
| 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 | // Hack for empty string query param, which, for whatever reason, happens |
| 174 | // in a test. Parsing drops empty key params (which might not really be necessary). |
| 175 | // It's probably really a test issue but I don't have the time to fix it... |
| 176 | k ||= 'ɵ'; |
| 177 | const tree = new UrlTree(); |
| 178 | tree.queryParams = {[k]: v}; |
| 179 | return urlSerializer.parse(urlSerializer.serialize(tree)).queryParams[k]; |
| 180 | } |
| 181 | |
| 182 | function tree( |
| 183 | oldRoot: UrlSegmentGroup, |