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

Function replaceSegment

packages/router/src/create_url_tree.ts:226–241  ·  view source on GitHub ↗

* Replaces the `oldSegment` which is located in some child of the `current` with the `newSegment`. * This also has the effect of creating new `UrlSegmentGroup` copies to update references. This * shouldn't be necessary but the fallback logic for an invalid ActivatedRoute in the creation uses * th

(
  current: UrlSegmentGroup,
  oldSegment: UrlSegmentGroup,
  newSegment: UrlSegmentGroup,
)

Source from the content-addressed store, hash-verified

224 * value.
225 */
226function replaceSegment(
227 current: UrlSegmentGroup,
228 oldSegment: UrlSegmentGroup,
229 newSegment: UrlSegmentGroup,
230): UrlSegmentGroup {
231 // Keyed by outlet name, which can be `__proto__`, so use a null-prototype map.
232 const children: {[key: string]: UrlSegmentGroup} = Object.create(null);
233 Object.entries(current.children).forEach(([outletName, c]) => {
234 if (c === oldSegment) {
235 children[outletName] = newSegment;
236 } else {
237 children[outletName] = replaceSegment(c, oldSegment, newSegment);
238 }
239 });
240 return new UrlSegmentGroup(current.segments, children);
241}
242
243class Navigation {
244 constructor(

Callers 1

treeFunction · 0.85

Calls 3

createMethod · 0.65
forEachMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected