MCPcopy
hub / github.com/angular/angular / processChildren

Method processChildren

packages/router/src/recognize.ts:188–233  ·  view source on GitHub ↗

* Matches every child outlet in the `segmentGroup` to a `Route` in the config. Returns `null` 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 against t

(
    injector: EnvironmentInjector,
    config: Route[],
    segmentGroup: UrlSegmentGroup,
    parentRoute: ActivatedRouteSnapshot,
  )

Source from the content-addressed store, hash-verified

186 * config.
187 */
188 async processChildren(
189 injector: EnvironmentInjector,
190 config: Route[],
191 segmentGroup: UrlSegmentGroup,
192 parentRoute: ActivatedRouteSnapshot,
193 ): Promise<TreeNode<ActivatedRouteSnapshot>[]> {
194 // Expand outlets one at a time, starting with the primary outlet. We need to do it this way
195 // because an absolute redirect from the primary outlet takes precedence.
196 const childOutlets: string[] = [];
197 for (const child of Object.keys(segmentGroup.children)) {
198 if (child === 'primary') {
199 childOutlets.unshift(child);
200 } else {
201 childOutlets.push(child);
202 }
203 }
204
205 let children: TreeNode<ActivatedRouteSnapshot>[] = [];
206 for (const childOutlet of childOutlets) {
207 const child = segmentGroup.children[childOutlet];
208 // Sort the config so that routes with outlets that match the one being activated
209 // appear first, followed by routes for other outlets, which might match if they have
210 // an empty path.
211 const sortedConfig = sortByMatchingOutlets(config, childOutlet);
212 const outletChildren = await this.processSegmentGroup(
213 injector,
214 sortedConfig,
215 child,
216 childOutlet,
217 parentRoute,
218 );
219 children.push(...outletChildren);
220 }
221
222 // Because we may have matched two outlets to the same empty path segment, we can have
223 // multiple activated results for the same outlet. We should merge the children of
224 // these results so the final return value is only one `TreeNode` per outlet.
225 const mergedChildren = mergeEmptyPathMatches(children);
226 if (typeof ngDevMode === 'undefined' || ngDevMode) {
227 // This should really never happen - we are only taking the first match for each
228 // outlet and merge the empty path matches.
229 checkOutletNameUniqueness(mergedChildren);
230 }
231 sortActivatedRouteSnapshots(mergedChildren);
232 return mergedChildren;
233 }
234
235 async processSegment(
236 injector: EnvironmentInjector,

Callers 2

processSegmentGroupMethod · 0.95

Calls 7

processSegmentGroupMethod · 0.95
sortByMatchingOutletsFunction · 0.90
mergeEmptyPathMatchesFunction · 0.85
keysMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected