Skip to content
Closed
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
19 changes: 17 additions & 2 deletions packages/angular/ssr/src/routes/ng-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import { APP_BASE_HREF, PlatformLocation } from '@angular/common';
import { ApplicationRef, Compiler, Injector, runInInjectionContext, ɵConsole } from '@angular/core';
import { INITIAL_CONFIG, platformServer } from '@angular/platform-server';
import { Route, Router, ɵloadChildren as loadChildrenHelper } from '@angular/router';
import { ROUTES, Route, Router, ɵloadChildren as loadChildrenHelper } from '@angular/router';
import { ServerAssets } from '../assets';
import { Console } from '../console';
import { AngularAppManifest, getAngularAppManifest } from '../manifest';
Expand All @@ -25,6 +25,12 @@ import {
} from './route-config';
import { RouteTree, RouteTreeNodeMetadata } from './route-tree';

/**
* Constant representing the path for route extraction.
* This path is used during the route extraction process and does not affect the application's actual routing behavior.
*/
const EXTRACT_ROUTES_PATH = 'ng-routes-internal';

/**
* Regular expression to match segments preceded by a colon in a string.
*/
Expand Down Expand Up @@ -407,7 +413,16 @@ export async function getRoutesFromAngularRouterConfig(
const platformRef = platformServer([
{
provide: INITIAL_CONFIG,
useValue: { document, url: `${protocol}//${host}/` },
// The route below is intentionally configured with a non-existent path
// to prevent the root route from rendering during the route extraction process.
useValue: { document, url: `${protocol}//${host}/${EXTRACT_ROUTES_PATH}` },
},
{
provide: ROUTES,
multi: true,
// Adds an 'internal' route to extract routes.
// This route doesn't perform any action but ensures the use of a non-existent path to avoid route mismatch errors in Angular router.
useValue: [EXTRACT_ROUTES_PATH],
},
{
provide: ɵConsole,
Expand Down
Loading