* 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, )
| 224 | * value. |
| 225 | */ |
| 226 | function 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 | |
| 243 | class Navigation { |
| 244 | constructor( |