MCPcopy Create free account
hub / github.com/angular/angular / serialize

Method serialize

packages/router/src/url_tree.ts:480–498  ·  view source on GitHub ↗

Converts a `UrlTree` into a url

(tree: UrlTree)

Source from the content-addressed store, hash-verified

478
479 /** Converts a `UrlTree` into a url */
480 serialize(tree: UrlTree): string {
481 let segment = `/${serializeSegment(tree.root, true)}`;
482 if (isProtocolRelative(segment)) {
483 if (typeof ngDevMode === 'undefined' || ngDevMode) {
484 console.warn(
485 formatRuntimeError(
486 RuntimeErrorCode.PROTOCOL_RELATIVE_URL_NOT_ALLOWED,
487 `Cannot serialize a UrlTree that would produce a protocol-relative URL. Falling back to '/' instead.`,
488 ),
489 );
490 }
491 segment = '/';
492 }
493 const query = serializeQueryParams(tree.queryParams);
494 const fragment =
495 typeof tree.fragment === `string` ? `#${encodeUriFragment(tree.fragment)}` : '';
496
497 return `${segment}${query}${fragment}`;
498 }
499}
500
501const DUMMY_BASE_URL = 'http://fake';

Callers 1

expectTreeToBeFunction · 0.95

Calls 6

serializeSegmentFunction · 0.85
isProtocolRelativeFunction · 0.85
formatRuntimeErrorFunction · 0.85
serializeQueryParamsFunction · 0.85
encodeUriFragmentFunction · 0.85
warnMethod · 0.65

Tested by 1

expectTreeToBeFunction · 0.76