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

Function serializeSegment

packages/router/src/url_tree.ts:524–558  ·  view source on GitHub ↗
(segment: UrlSegmentGroup, root: boolean)

Source from the content-addressed store, hash-verified

522}
523
524function serializeSegment(segment: UrlSegmentGroup, root: boolean): string {
525 if (!segment.hasChildren()) {
526 return serializePaths(segment);
527 }
528
529 if (root) {
530 const primary = segment.children[PRIMARY_OUTLET]
531 ? serializeSegment(segment.children[PRIMARY_OUTLET], false)
532 : '';
533 const children: string[] = [];
534
535 Object.entries(segment.children).forEach(([k, v]) => {
536 if (k !== PRIMARY_OUTLET) {
537 children.push(`${k}:${serializeSegment(v, false)}`);
538 }
539 });
540
541 return children.length > 0 ? `${primary}(${children.join('//')})` : primary;
542 } else {
543 // use no parenthesis if the only child is a primary outlet route
544 if (Object.keys(segment.children).length === 1 && segment.children[PRIMARY_OUTLET] != null) {
545 return `${serializePaths(segment)}/${serializeSegment(segment.children[PRIMARY_OUTLET], false)}`;
546 }
547
548 const children = mapChildrenIntoArray(segment, (v: UrlSegmentGroup, k: string) => {
549 if (k === PRIMARY_OUTLET) {
550 return [escapeOutletDelimiter(serializeSegment(segment.children[PRIMARY_OUTLET], false))];
551 }
552
553 return [`${k}:${serializeSegment(v, false)}`];
554 });
555
556 return `${serializePaths(segment)}/(${children.join('//')})`;
557 }
558}
559
560/**
561 * Inside a parenthesized group, the parser distinguishes a named outlet (`name:path`) from the

Callers 1

serializeMethod · 0.85

Calls 9

serializePathsFunction · 0.85
mapChildrenIntoArrayFunction · 0.85
escapeOutletDelimiterFunction · 0.85
joinMethod · 0.65
keysMethod · 0.65
hasChildrenMethod · 0.45
forEachMethod · 0.45
entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected