diff --git a/src/options.ts b/src/options.ts index 585d3ffba7..bd76b5bcd2 100644 --- a/src/options.ts +++ b/src/options.ts @@ -79,6 +79,7 @@ const NitroDefaults: NitroConfig = { errorHandler: "#internal/nitro/error", routeRules: {}, prerender: { + autoSubfolderIndex: true, concurrency: 1, interval: 0, failOnError: false, diff --git a/src/prerender.ts b/src/prerender.ts index a800ccc636..9bb7ca293d 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -214,8 +214,12 @@ export async function prerender(nitro: Nitro) { const isImplicitHTML = !route.endsWith(".html") && contentType.includes("html"); const routeWithIndex = route.endsWith("/") ? route + "index" : route; + const htmlPath = + route.endsWith("/") || nitro.options.prerender.autoSubfolderIndex + ? joinURL(route, "index.html") + : route + ".html"; _route.fileName = withoutBase( - isImplicitHTML ? joinURL(route, "index.html") : routeWithIndex, + isImplicitHTML ? htmlPath : routeWithIndex, nitro.options.baseURL ); // Allow overriding content-type in `prerender:generate` hook diff --git a/src/types/nitro.ts b/src/types/nitro.ts index 6055490476..054388e97a 100644 --- a/src/types/nitro.ts +++ b/src/types/nitro.ts @@ -283,6 +283,10 @@ export interface NitroOptions extends PresetOptions { errorHandler: string; devErrorHandler: NitroErrorHandler; prerender: { + /** + * Prerender HTML routes within subfolders (`/test` would produce `/test/index.html`) + */ + autoSubfolderIndex: boolean; concurrency: number; interval: number; crawlLinks: boolean;