diff --git a/goldens/public-api/angular/ssr/index.api.md b/goldens/public-api/angular/ssr/index.api.md index 81764fcc1f62..d165dcf6a7e2 100644 --- a/goldens/public-api/angular/ssr/index.api.md +++ b/goldens/public-api/angular/ssr/index.api.md @@ -6,6 +6,7 @@ import { DefaultExport } from '@angular/router'; import { EnvironmentProviders } from '@angular/core'; +import { InjectionToken } from '@angular/core'; import { Provider } from '@angular/core'; import { Type } from '@angular/core'; @@ -19,6 +20,9 @@ export class AngularAppEngine { // @public export function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction; +// @public +export const DURING_ROUTE_DISCOVERY: InjectionToken; + // @public export enum PrerenderFallback { Client = 1, diff --git a/packages/angular/ssr/public_api.ts b/packages/angular/ssr/public_api.ts index e685f4ceabe3..b3e064a82b7b 100644 --- a/packages/angular/ssr/public_api.ts +++ b/packages/angular/ssr/public_api.ts @@ -24,3 +24,5 @@ export { type ServerRouteServer, type ServerRouteCommon, } from './src/routes/route-config'; + +export { DURING_ROUTE_DISCOVERY } from './src/routes/ng-routes'; diff --git a/packages/angular/ssr/src/routes/ng-routes.ts b/packages/angular/ssr/src/routes/ng-routes.ts index b60e704371a4..286e26ba05dc 100644 --- a/packages/angular/ssr/src/routes/ng-routes.ts +++ b/packages/angular/ssr/src/routes/ng-routes.ts @@ -11,6 +11,7 @@ import { ApplicationRef, Compiler, EnvironmentInjector, + InjectionToken, Injector, createEnvironmentInjector, runInInjectionContext, @@ -23,6 +24,7 @@ import { Router, ɵloadChildren as loadChildrenHelper, } from '@angular/router'; + import { ServerAssets } from '../assets'; import { Console } from '../console'; import { AngularAppManifest, getAngularAppManifest } from '../manifest'; @@ -39,6 +41,16 @@ import { } from './route-config'; import { RouteTree, RouteTreeNodeMetadata } from './route-tree'; +/** + * A DI token that indicates whether the application is in the process of discovering routes. + * + * This token is provided with the value `true` when route discovery is active, allowing other + * parts of the application to conditionally execute logic. For example, it can be used to + * disable features or behaviors that are not necessary or might interfere with the route + * discovery process. + */ +export const DURING_ROUTE_DISCOVERY = new InjectionToken('DURING_ROUTE_DISCOVERY'); + interface Route extends AngularRoute { ɵentryName?: string; } @@ -623,6 +635,10 @@ export async function getRoutesFromAngularRouterConfig( provide: ɵENABLE_ROOT_COMPONENT_BOOTSTRAP, useValue: false, }, + { + provide: DURING_ROUTE_DISCOVERY, + useValue: true, + }, ]); try {