From 5dc365af3847a19b34fab2b0c3923dc8b9d4987f Mon Sep 17 00:00:00 2001 From: Alan Agius <17563226+alan-agius4@users.noreply.github.com> Date: Fri, 13 Feb 2026 15:22:21 +0000 Subject: [PATCH] feat(@angular/ssr): introduce DI token to signal route discovery process A new DI token, `DURING_ROUTE_DISCOVERY`, is introduced to provide a clear signal for when the application is operating in route discovery mode. This token is provided with the value `true` within the route extraction providers. Other services and components can inject this token to conditionally alter their behavior, for instance, to disable functionality that is not required or could interfere with the route discovery process. Closes #32474 --- goldens/public-api/angular/ssr/index.api.md | 4 ++++ packages/angular/ssr/public_api.ts | 2 ++ packages/angular/ssr/src/routes/ng-routes.ts | 16 ++++++++++++++++ 3 files changed, 22 insertions(+) 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 {