mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(nuxt): extend nitro routes instead of overriding (#5828)
This commit is contained in:
parent
1840b96335
commit
56a3f1b615
@ -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<string>()
|
||||
const prerenderRoutes = new Set<string>()
|
||||
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)
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user