diff --git a/packages/angular/build/src/builders/application/options.ts b/packages/angular/build/src/builders/application/options.ts index 7cf261c47295..1a7502c9bd43 100644 --- a/packages/angular/build/src/builders/application/options.ts +++ b/packages/angular/build/src/builders/application/options.ts @@ -320,10 +320,16 @@ export async function normalizeOptions( * If SSR is activated, create a distinct entry file for the `index.html`. * This is necessary because numerous server/cloud providers automatically serve the `index.html` as a static file * if it exists (handling SSG). + * * For instance, accessing `foo.com/` would lead to `foo.com/index.html` being served instead of hitting the server. + * + * This approach can also be applied to service workers, where the `index.csr.html` is served instead of the prerendered `index.html`. */ const indexBaseName = path.basename(options.index); - indexOutput = ssrOptions && indexBaseName === 'index.html' ? INDEX_HTML_CSR : indexBaseName; + indexOutput = + (ssrOptions || prerenderOptions) && indexBaseName === 'index.html' + ? INDEX_HTML_CSR + : indexBaseName; } else { indexOutput = options.index.output || 'index.html'; } diff --git a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts index 6da698b2b403..50a7d32a7c1b 100644 --- a/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts +++ b/tests/legacy-cli/e2e/tests/build/prerender/discover-routes-ngmodule.ts @@ -118,16 +118,25 @@ export default async function () { return; } - await ng('build', projectName, '--configuration=production', '--prerender'); + await ng('build', projectName, '--configuration=production', '--prerender', '--no-ssr'); await runExpects(); // Test also JIT mode. - await ng('build', projectName, '--configuration=development', '--prerender', '--no-aot'); + await ng( + 'build', + projectName, + '--configuration=development', + '--prerender', + '--no-ssr', + '--no-aot', + ); + await runExpects(); async function runExpects(): Promise { const expects: Record = { 'index.html': 'one works!', + 'index.csr.html': '', 'two/index.html': 'router-outlet', 'two/two-child-one/index.html': 'two-child-one works!', 'two/two-child-two/index.html': 'two-child-two works!',