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