(segment: UrlSegmentGroup, root: boolean)
| 476 | } |
| 477 | |
| 478 | function serializeSegment(segment: UrlSegmentGroup, root: boolean): string { |
| 479 | if (!segment.hasChildren()) { |
| 480 | return serializePaths(segment); |
| 481 | } |
| 482 | |
| 483 | if (root) { |
| 484 | const primary = segment.children[PRIMARY_OUTLET] |
| 485 | ? serializeSegment(segment.children[PRIMARY_OUTLET], false) |
| 486 | : ''; |
| 487 | const children: string[] = []; |
| 488 | |
| 489 | Object.entries(segment.children).forEach(([k, v]) => { |
| 490 | if (k !== PRIMARY_OUTLET) { |
| 491 | children.push(`${k}:${serializeSegment(v, false)}`); |
| 492 | } |
| 493 | }); |
| 494 | |
| 495 | return children.length > 0 ? `${primary}(${children.join('//')})` : primary; |
| 496 | } else { |
| 497 | const children = mapChildrenIntoArray(segment, (v: UrlSegmentGroup, k: string) => { |
| 498 | if (k === PRIMARY_OUTLET) { |
| 499 | return [serializeSegment(segment.children[PRIMARY_OUTLET], false)]; |
| 500 | } |
| 501 | |
| 502 | return [`${k}:${serializeSegment(v, false)}`]; |
| 503 | }); |
| 504 | |
| 505 | // use no parenthesis if the only child is a primary outlet route |
| 506 | if (Object.keys(segment.children).length === 1 && segment.children[PRIMARY_OUTLET] != null) { |
| 507 | return `${serializePaths(segment)}/${children[0]}`; |
| 508 | } |
| 509 | |
| 510 | return `${serializePaths(segment)}/(${children.join('//')})`; |
| 511 | } |
| 512 | } |
| 513 | |
| 514 | /** |
| 515 | * Encodes a URI string with the default encoding. This function will only ever be called from |
no test coverage detected