MCPcopy Index your code
hub / github.com/angular/angular-cli / traverseRoutesConfig

Function traverseRoutesConfig

packages/angular/ssr/src/routes/ng-routes.ts:255–353  ·  view source on GitHub ↗

* Traverses an array of route configurations to generate route tree node metadata. * * This function processes each route and its children, handling redirects, SSG (Static Site Generation) settings, * and lazy-loaded routes. It yields route metadata for each route and its potential variants. *

(options: {
  routes: Route[];
  compiler: Compiler;
  parentInjector: Injector;
  parentRoute: string;
  serverConfigRouteTree?: RouteTree<ServerConfigRouteTreeAdditionalMetadata>;
  invokeGetPrerenderParams: boolean;
  includePrerenderFallbackRoutes: boolean;
  entryPointToBrowserMapping?: EntryPointToBrowserMapping;
  parentPreloads?: readonly string[];
})

Source from the content-addressed store, hash-verified

253 * @returns An async iterable iterator yielding either route tree node metadata or an error object with an error message.
254 */
255async function* traverseRoutesConfig(options: {
256 routes: Route[];
257 compiler: Compiler;
258 parentInjector: Injector;
259 parentRoute: string;
260 serverConfigRouteTree?: RouteTree<ServerConfigRouteTreeAdditionalMetadata>;
261 invokeGetPrerenderParams: boolean;
262 includePrerenderFallbackRoutes: boolean;
263 entryPointToBrowserMapping?: EntryPointToBrowserMapping;
264 parentPreloads?: readonly string[];
265}): AsyncIterableIterator<RouteTreeNodeMetadata | { error: string }> {
266 const { routes: routeConfigs, parentPreloads, parentRoute, serverConfigRouteTree } = options;
267
268 for (const route of routeConfigs) {
269 const { matcher, path = matcher ? '**' : '' } = route;
270 const currentRoutePath = joinUrlParts(parentRoute, path);
271
272 if (matcher && serverConfigRouteTree) {
273 const matches: (RouteTreeNodeMetadata & ServerConfigRouteTreeAdditionalMetadata)[] = [];
274 for (const matchedMetaData of serverConfigRouteTree.traverse()) {
275 if (matchedMetaData.route.startsWith(currentRoutePath)) {
276 matches.push(matchedMetaData);
277 }
278 }
279
280 if (!matches.length) {
281 const matchedMetaData = serverConfigRouteTree.match(currentRoutePath);
282 if (matchedMetaData) {
283 matches.push(matchedMetaData);
284 }
285 }
286
287 for (const matchedMetaData of matches) {
288 matchedMetaData.presentInClientRouter = true;
289 if (matchedMetaData.renderMode === RenderMode.Prerender) {
290 yield {
291 error:
292 `The route '${stripLeadingSlash(currentRoutePath)}' is set for prerendering but has a defined matcher. ` +
293 `Routes with matchers cannot use prerendering. Please specify a different 'renderMode'.`,
294 };
295 continue;
296 }
297
298 yield* handleRoute({
299 ...options,
300 currentRoutePath,
301 route,
302 metadata: {
303 ...matchedMetaData,
304 preload: parentPreloads,
305 route: matchedMetaData.route,
306 presentInClientRouter: undefined,
307 },
308 });
309 }
310
311 if (!matches.length) {
312 yield {

Callers 2

handleRouteFunction · 0.85

Calls 7

joinUrlPartsFunction · 0.90
stripLeadingSlashFunction · 0.90
addTrailingSlashFunction · 0.90
handleRouteFunction · 0.85
traverseMethod · 0.80
pushMethod · 0.45
matchMethod · 0.45

Tested by

no test coverage detected