Skip to content

Commit

Permalink
fix(@angular/build): prevent prerendering of catch-all routes
Browse files Browse the repository at this point in the history
Updated the build process to exclude catch-all routes from being prerendered.
  • Loading branch information
alan-agius4 committed Sep 24, 2024
1 parent 158774a commit a995c8e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ export async function prerenderPages(
const serializableRouteTreeNodeForPrerender: WritableSerializableRouteTreeNode = [];
for (const metadata of serializableRouteTreeNode) {
if (outputMode !== OutputMode.Static && metadata.redirectTo) {
// Skip redirects if output mode is not static.
continue;
}

if (metadata.route.includes('*')) {
// Skip catch all routes from prerender.
continue;
}

Expand All @@ -129,7 +135,6 @@ export async function prerenderPages(
case RouteRenderMode.Prerender:
case RouteRenderMode.AppShell:
serializableRouteTreeNodeForPrerender.push(metadata);

break;
case RouteRenderMode.Server:
if (outputMode === OutputMode.Static) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { join } from 'node:path';
import { expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
import { expectFileNotToExist, expectFileToMatch, replaceInFile, writeFile } from '../../utils/fs';
import { noSilentNg, silentNg } from '../../utils/process';
import { setupProjectWithSSRAppEngine } from './setup';
import { existsSync } from 'node:fs';
Expand Down Expand Up @@ -36,6 +36,10 @@ export default async function () {
path: 'ssg/:id',
component: SsgWithParamsComponent,
},
{
path: '**',
component: HomeComponent,
},
];
`,
);
Expand Down Expand Up @@ -100,4 +104,7 @@ export default async function () {
!existsSync('dist/test-project/server'),
'Server directory should not exist when output-mode is static',
);

// Should not prerender the catch all
await expectFileNotToExist(join('dist/test-project/browser/**/index.html'));
}

0 comments on commit a995c8e

Please sign in to comment.