Skip to content

Commit 5dc365a

Browse files
committed
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
1 parent 9c5901e commit 5dc365a

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

goldens/public-api/angular/ssr/index.api.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import { DefaultExport } from '@angular/router';
88
import { EnvironmentProviders } from '@angular/core';
9+
import { InjectionToken } from '@angular/core';
910
import { Provider } from '@angular/core';
1011
import { Type } from '@angular/core';
1112

@@ -19,6 +20,9 @@ export class AngularAppEngine {
1920
// @public
2021
export function createRequestHandler(handler: RequestHandlerFunction): RequestHandlerFunction;
2122

23+
// @public
24+
export const DURING_ROUTE_DISCOVERY: InjectionToken<boolean>;
25+
2226
// @public
2327
export enum PrerenderFallback {
2428
Client = 1,

packages/angular/ssr/public_api.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ export {
2424
type ServerRouteServer,
2525
type ServerRouteCommon,
2626
} from './src/routes/route-config';
27+
28+
export { DURING_ROUTE_DISCOVERY } from './src/routes/ng-routes';

packages/angular/ssr/src/routes/ng-routes.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
ApplicationRef,
1212
Compiler,
1313
EnvironmentInjector,
14+
InjectionToken,
1415
Injector,
1516
createEnvironmentInjector,
1617
runInInjectionContext,
@@ -23,6 +24,7 @@ import {
2324
Router,
2425
ɵloadChildren as loadChildrenHelper,
2526
} from '@angular/router';
27+
2628
import { ServerAssets } from '../assets';
2729
import { Console } from '../console';
2830
import { AngularAppManifest, getAngularAppManifest } from '../manifest';
@@ -39,6 +41,16 @@ import {
3941
} from './route-config';
4042
import { RouteTree, RouteTreeNodeMetadata } from './route-tree';
4143

44+
/**
45+
* A DI token that indicates whether the application is in the process of discovering routes.
46+
*
47+
* This token is provided with the value `true` when route discovery is active, allowing other
48+
* parts of the application to conditionally execute logic. For example, it can be used to
49+
* disable features or behaviors that are not necessary or might interfere with the route
50+
* discovery process.
51+
*/
52+
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY');
53+
4254
interface Route extends AngularRoute {
4355
ɵentryName?: string;
4456
}
@@ -623,6 +635,10 @@ export async function getRoutesFromAngularRouterConfig(
623635
provide: ɵENABLE_ROOT_COMPONENT_BOOTSTRAP,
624636
useValue: false,
625637
},
638+
{
639+
provide: DURING_ROUTE_DISCOVERY,
640+
useValue: true,
641+
},
626642
]);
627643

628644
try {

0 commit comments

Comments
 (0)