* 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, )
| 221 | * value. |
| 222 | */ |
| 223 | function 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 | |
| 240 | class Navigation { |
| 241 | constructor( |