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

Function createNewSegmentGroup

packages/router/src/create_url_tree.ts:512–546  ·  view source on GitHub ↗
(
  segmentGroup: UrlSegmentGroup,
  startIndex: number,
  commands: readonly any[],
)

Source from the content-addressed store, hash-verified

510}
511
512function createNewSegmentGroup(
513 segmentGroup: UrlSegmentGroup,
514 startIndex: number,
515 commands: readonly any[],
516): UrlSegmentGroup {
517 const paths = segmentGroup.segments.slice(0, startIndex);
518
519 let i = 0;
520 while (i < commands.length) {
521 const command = commands[i];
522 if (isCommandWithOutlets(command)) {
523 const children = createNewSegmentChildren(command.outlets);
524 return new UrlSegmentGroup(paths, children);
525 }
526
527 // if we start with an object literal, we need to reuse the path part from the segment
528 if (i === 0 && isMatrixParams(commands[0])) {
529 const p = segmentGroup.segments[startIndex];
530 paths.push(new UrlSegment(p.path, stringify(commands[0])));
531 i++;
532 continue;
533 }
534
535 const curr = isCommandWithOutlets(command) ? command.outlets[PRIMARY_OUTLET] : `${command}`;
536 const next = i < commands.length - 1 ? commands[i + 1] : null;
537 if (curr && next && isMatrixParams(next)) {
538 paths.push(new UrlSegment(curr, stringify(next)));
539 i += 2;
540 } else {
541 paths.push(new UrlSegment(curr, {}));
542 i++;
543 }
544 }
545 return new UrlSegmentGroup(paths, {});
546}
547
548function createNewSegmentChildren(outlets: {[name: string]: readonly unknown[] | string}): {
549 [outlet: string]: UrlSegmentGroup;

Callers 2

updateSegmentGroupFunction · 0.85
createNewSegmentChildrenFunction · 0.85

Calls 5

isCommandWithOutletsFunction · 0.85
createNewSegmentChildrenFunction · 0.85
isMatrixParamsFunction · 0.85
stringifyFunction · 0.70
pushMethod · 0.45

Tested by

no test coverage detected