* Matches every child outlet in the `segmentGroup` to a `Route` in the config. Returns `NoMatch` * if we cannot find a match for _any_ of the children. * * @param config - The `Routes` to match against * @param segmentGroup - The `UrlSegmentGroup` whose children need to be matched agains
(
injector: EnvironmentInjector,
config: Route[],
segmentGroup: UrlSegmentGroup,
parentRoute: ActivatedRouteSnapshot,
)
| 205 | * config. |
| 206 | */ |
| 207 | async processChildren( |
| 208 | injector: EnvironmentInjector, |
| 209 | config: Route[], |
| 210 | segmentGroup: UrlSegmentGroup, |
| 211 | parentRoute: ActivatedRouteSnapshot, |
| 212 | ): Promise<TreeNode<ActivatedRouteSnapshot>[] | NoMatch | AbsoluteRedirect> { |
| 213 | // Expand outlets one at a time, starting with the primary outlet. We need to do it this way |
| 214 | // because an absolute redirect from the primary outlet takes precedence. |
| 215 | const childOutlets: string[] = []; |
| 216 | for (const child of Object.keys(segmentGroup.children)) { |
| 217 | if (child === 'primary') { |
| 218 | childOutlets.unshift(child); |
| 219 | } else { |
| 220 | childOutlets.push(child); |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | let children: TreeNode<ActivatedRouteSnapshot>[] = []; |
| 225 | for (const childOutlet of childOutlets) { |
| 226 | const child = segmentGroup.children[childOutlet]; |
| 227 | // Sort the config so that routes with outlets that match the one being activated |
| 228 | // appear first, followed by routes for other outlets, which might match if they have |
| 229 | // an empty path. |
| 230 | const sortedConfig = sortByMatchingOutlets(config, childOutlet); |
| 231 | const outletChild = await this.processSegment( |
| 232 | injector, |
| 233 | sortedConfig, |
| 234 | child, |
| 235 | child.segments, |
| 236 | childOutlet, |
| 237 | true, |
| 238 | parentRoute, |
| 239 | ); |
| 240 | if (outletChild instanceof NoMatch || outletChild instanceof AbsoluteRedirect) { |
| 241 | return outletChild; |
| 242 | } |
| 243 | if (outletChild instanceof TreeNode) { |
| 244 | children.push(outletChild); |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Because we may have matched two outlets to the same empty path segment, we can have |
| 249 | // multiple activated results for the same outlet. We should merge the children of |
| 250 | // these results so the final return value is only one `TreeNode` per outlet. |
| 251 | const mergedChildren = mergeEmptyPathMatches(children); |
| 252 | sortActivatedRouteSnapshots(mergedChildren); |
| 253 | return mergedChildren; |
| 254 | } |
| 255 | |
| 256 | async processSegment( |
| 257 | injector: EnvironmentInjector, |
no test coverage detected