Visitar URL original
feat(@angular/build): add `prerender.format` option to prerender routes as `<route>.html` by JohannesHoppe · Pull Request #34180 · angular/angular-cli · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
feat(@angular/build): add prerender.format option to prerender rout…
…es as `<route>.html`

The new `format` property of the `prerender` option accepts `directory` (default, unchanged
behavior) and `file`, like the `build.format` option of Astro. With `file`, routes are written
to `<route>.html` instead of `<route>/index.html`. Static hosts serve `<route>/index.html` under
`/<route>/`, so a request to `/<route>` is first redirected to the URL with a trailing slash,
which the Angular router then removes again. Hosts that serve `<route>.html` for `/<route>`
respond without that redirect.

The root route (after removing the `baseHref` option) is still written to `index.html`. Static
redirect pages follow the same layout. `prerender.format` is also considered when `outputMode`
is set, while `prerender.routesFile` and `prerender.discoverRoutes` are not.

`file` is only considered when the build does not produce a server, because the `@angular/ssr`
runtime looks up prerendered pages as `<route>/index.html`. In that case, a warning is reported
and routes are written to `<route>/index.html`.

Closes #29173
  • Loading branch information
JohannesHoppe committed Oct 8, 2026
commit 4f2ca8ed37cbb4aef08c9f94cd5650542607e5d8
1 change: 1 addition & 0 deletions goldens/public-api/angular/build/index.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export type ApplicationBuilderOptions = {
poll?: number;
polyfills?: string[];
prerender?: PrerenderUnion;
prerenderFormat?: PrerenderFormat;
preserveSymlinks?: boolean;
progress?: boolean;
scripts?: ScriptElement[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function executePostBundleSteps(
outputMode,
serverEntryPoint,
prerenderOptions,
prerenderFormat,
appShellOptions,
publicPath,
workspaceRoot,
Expand Down Expand Up @@ -168,6 +169,8 @@ export async function executePostBundleSteps(
[...outputFiles, ...additionalOutputFiles],
assetFiles,
outputMode,
prerenderFormat,
indexHtmlOptions.output,
sourcemapOptions.scripts,
maxWorkers,
);
Expand Down
16 changes: 16 additions & 0 deletions packages/angular/build/src/builders/application/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
OutputMode,
OutputPathClass,
Platform,
PrerenderFormat,
} from './schema';

/**
Expand Down Expand Up @@ -342,6 +343,20 @@ export async function normalizeOptions(
options.outputMode === OutputMode.Static,
};

let prerenderFormat = options.prerenderFormat ?? PrerenderFormat.Directory;
if (prerenderFormat === PrerenderFormat.File && !outputOptions.ignoreServer) {
// The server runtime of '@angular/ssr' looks up prerendered pages as '<route>/index.html'.
// The warning is only relevant when pages are actually prerendered, which the dev-server skips.
if ((prerenderOptions || appShellOptions) && !(options.partialSSRBuild || usePartialSsrBuild)) {
Comment thread
JohannesHoppe marked this conversation as resolved.
Outdated
context.logger.warn(
'The "prerenderFormat" option set to "file" is not considered when the build produces a ' +
'server ("outputMode" set to "server", or "ssr" without "outputMode").',
);
}

prerenderFormat = PrerenderFormat.Directory;
}

const outputNames = {
bundles:
options.outputHashing === OutputHashing.All || options.outputHashing === OutputHashing.Bundles
Expand Down Expand Up @@ -492,6 +507,7 @@ export async function normalizeOptions(
subresourceIntegrity,
serverEntryPoint,
prerenderOptions,
prerenderFormat,
appShellOptions,
outputMode,
ssrOptions,
Expand Down
6 changes: 6 additions & 0 deletions packages/angular/build/src/builders/application/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -587,6 +587,12 @@
}
]
},
"prerenderFormat": {
Comment thread
JohannesHoppe marked this conversation as resolved.
Outdated
"type": "string",
"description": "Defines the file layout of prerendered (SSG) pages. 'directory': '/foo' is written to 'foo/index.html'. 'file': '/foo' is written to 'foo.html', which some hosting services serve for '/foo' without a redirect to '/foo/'. The root route of the application and of each locale is always written to 'index.html'. Routes that cannot be written safely to '<route>.html' keep '<route>/index.html' with a warning. Only considered when the build does not produce a server.",
"enum": ["directory", "file"],
"default": "directory"
},
"ssr": {
"description": "Server side render (SSR) pages of your application during runtime.",
"default": false,
Expand Down
Loading