MCPcopy Index your code
hub / github.com/angular/angular-cli / constructSerializedUrl

Function constructSerializedUrl

packages/angular/ssr/src/utils/ng.ts:211–229  ·  view source on GitHub ↗

* Constructs a normalized and serialized URL string from its components. * * This function uses the provided `Router` instance to parse and serialize the URL, * ensuring that the resulting string is consistent with the router's configuration. * It also handles the optional `prefix` parameter to

(
  router: Router,
  url: { pathname: string; search: string; hash: string },
  prefix?: string | null,
)

Source from the content-addressed store, hash-verified

209 * This is important for the URL to be correctly parsed and serialized by the router as it might have different encodings.
210 */
211function constructSerializedUrl(
212 router: Router,
213 url: { pathname: string; search: string; hash: string },
214 prefix?: string | null,
215): string {
216 const { pathname, hash, search } = url;
217 const urlParts: string[] = [];
218 if (prefix && !addTrailingSlash(pathname).startsWith(addTrailingSlash(prefix))) {
219 urlParts.push(joinUrlParts(prefix, pathname));
220 } else {
221 urlParts.push(stripTrailingSlash(pathname));
222 }
223
224 urlParts.push(search, hash);
225
226 const urlTree = router.parseUrl(urlParts.join(''));
227
228 return router.serializeUrl(urlTree);
229}

Callers 1

renderAngularFunction · 0.85

Calls 4

addTrailingSlashFunction · 0.90
joinUrlPartsFunction · 0.90
stripTrailingSlashFunction · 0.90
pushMethod · 0.45

Tested by

no test coverage detected