Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions goldens/public-api/angular/ssr/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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';

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

// @public
export const DURING_ROUTE_DISCOVERY: InjectionToken<boolean>;

// @public
export enum PrerenderFallback {
Client = 1,
Expand Down
2 changes: 2 additions & 0 deletions packages/angular/ssr/public_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,5 @@ export {
type ServerRouteServer,
type ServerRouteCommon,
} from './src/routes/route-config';

export { DURING_ROUTE_DISCOVERY } from './src/routes/ng-routes';
16 changes: 16 additions & 0 deletions packages/angular/ssr/src/routes/ng-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
ApplicationRef,
Compiler,
EnvironmentInjector,
InjectionToken,
Injector,
createEnvironmentInjector,
runInInjectionContext,
Expand All @@ -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';
Expand All @@ -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<boolean>('DURING_ROUTE_DISCOVERY');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY');
export const DURING_ROUTE_DISCOVERY = new InjectionToken<boolean>('DURING_ROUTE_DISCOVERY', {
factory: () => false
});

Should this have a default value? As this will run in browser mode too I guess ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ohhh. Good catch.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: The naming feels a little awkward to me to start with "during". I wonder if IS_DISCOVERING_ROUTES or IS_BOOTSTRAPPING_FOR_ROUTES or something like that might be more clear as a boolean value? Up to you in the end.


interface Route extends AngularRoute {
ɵentryName?: string;
}
Expand Down Expand Up @@ -623,6 +635,10 @@ export async function getRoutesFromAngularRouterConfig(
provide: ɵENABLE_ROOT_COMPONENT_BOOTSTRAP,
useValue: false,
},
{
provide: DURING_ROUTE_DISCOVERY,
useValue: true,
},
]);

try {
Expand Down