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

Function handleSSGRoute

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

* Handles SSG (Static Site Generation) routes by invoking `getPrerenderParams` and yielding * all parameterized paths, returning any errors encountered. * * @param serverConfigRouteTree - The tree representing the server's routing setup. * @param redirectTo - Optional path to redirect to, if spe

(
  serverConfigRouteTree: RouteTree<ServerConfigRouteTreeAdditionalMetadata> | undefined,
  redirectTo: string | undefined,
  metadata: ServerConfigRouteTreeNodeMetadata,
  parentInjector: Injector,
  invokeGetPrerenderParams: boolean,
  includePrerenderFallbackRoutes: boolean,
)

Source from the content-addressed store, hash-verified

399 * @returns An async iterable iterator that yields route tree node metadata for each SSG path or errors.
400 */
401async function* handleSSGRoute(
402 serverConfigRouteTree: RouteTree<ServerConfigRouteTreeAdditionalMetadata> | undefined,
403 redirectTo: string | undefined,
404 metadata: ServerConfigRouteTreeNodeMetadata,
405 parentInjector: Injector,
406 invokeGetPrerenderParams: boolean,
407 includePrerenderFallbackRoutes: boolean,
408): AsyncIterableIterator<RouteTreeNodeMetadata | { error: string }> {
409 if (metadata.renderMode !== RenderMode.Prerender) {
410 throw new Error(
411 `'handleSSGRoute' was called for a route which rendering mode is not prerender.`,
412 );
413 }
414
415 const { route: currentRoutePath, fallback, ...meta } = metadata;
416 const getPrerenderParams = 'getPrerenderParams' in meta ? meta.getPrerenderParams : undefined;
417
418 if ('getPrerenderParams' in meta) {
419 delete meta['getPrerenderParams'];
420 }
421
422 if (redirectTo !== undefined) {
423 meta.redirectTo = resolveRedirectTo(currentRoutePath, redirectTo);
424 }
425
426 const isCatchAllRoute = CATCH_ALL_REGEXP.test(currentRoutePath);
427 if (
428 (isCatchAllRoute && !getPrerenderParams) ||
429 (!isCatchAllRoute && !URL_PARAMETER_REGEXP.test(currentRoutePath))
430 ) {
431 // Route has no parameters
432 yield {
433 ...meta,
434 route: currentRoutePath,
435 };
436
437 return;
438 }
439
440 if (invokeGetPrerenderParams) {
441 if (!getPrerenderParams) {
442 yield {
443 error:
444 `The '${stripLeadingSlash(currentRoutePath)}' route uses prerendering and includes parameters, but 'getPrerenderParams' ` +
445 `is missing. Please define 'getPrerenderParams' function for this route in your server routing configuration ` +
446 `or specify a different 'renderMode'.`,
447 };
448
449 return;
450 }
451
452 if (serverConfigRouteTree) {
453 // Automatically resolve dynamic parameters for nested routes.
454 const catchAllRoutePath = isCatchAllRoute
455 ? currentRoutePath
456 : joinUrlParts(currentRoutePath, '**');
457 const match = serverConfigRouteTree.match(catchAllRoutePath);
458 if (match && match.renderMode === RenderMode.Prerender && !('getPrerenderParams' in match)) {

Callers 1

handleRouteFunction · 0.85

Calls 7

stripLeadingSlashFunction · 0.90
joinUrlPartsFunction · 0.90
resolveRedirectToFunction · 0.85
getPrerenderParamsFunction · 0.85
insertMethod · 0.80
matchMethod · 0.45

Tested by

no test coverage detected