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

Function replaceSegment

packages/router/src/create_url_tree.ts:223–238  ·  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

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

Callers 1

treeFunction · 0.85

Calls 3

createMethod · 0.65
forEachMethod · 0.45
entriesMethod · 0.45

Tested by

no test coverage detected