diff --git a/packages/nuxt/src/pages/module.ts b/packages/nuxt/src/pages/module.ts index 65518a6a380..4dd56899c9d 100644 --- a/packages/nuxt/src/pages/module.ts +++ b/packages/nuxt/src/pages/module.ts @@ -54,29 +54,27 @@ export default defineNuxtModule({ // Prerender all non-dynamic page routes when generating app if (!nuxt.options.dev && nuxt.options._generate) { - const routes = new Set() + const prerenderRoutes = new Set() nuxt.hook('modules:done', () => { nuxt.hook('pages:extend', (pages) => { - routes.clear() - for (const path of nuxt.options.nitro.prerender?.routes || []) { - routes.add(path) - } + prerenderRoutes.clear() const processPages = (pages: NuxtPage[], currentPath = '/') => { for (const page of pages) { // Skip dynamic paths if (page.path.includes(':')) { continue } - - const path = joinURL(currentPath, page.path) - routes.add(path) - if (page.children) { processPages(page.children, path) } + const route = joinURL(currentPath, page.path) + prerenderRoutes.add(route) + if (page.children) { processPages(page.children, route) } } } processPages(pages) }) }) - nuxt.hook('nitro:build:before', (nitro) => { - nitro.options.prerender.routes = [...routes] + for (const route of nitro.options.prerender.routes || []) { + prerenderRoutes.add(route) + } + nitro.options.prerender.routes = Array.from(prerenderRoutes) }) }