mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 21:55:11 +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
|
// Prerender all non-dynamic page routes when generating app
|
||||||
if (!nuxt.options.dev && nuxt.options._generate) {
|
if (!nuxt.options.dev && nuxt.options._generate) {
|
||||||
const routes = new Set<string>()
|
const prerenderRoutes = new Set<string>()
|
||||||
nuxt.hook('modules:done', () => {
|
nuxt.hook('modules:done', () => {
|
||||||
nuxt.hook('pages:extend', (pages) => {
|
nuxt.hook('pages:extend', (pages) => {
|
||||||
routes.clear()
|
prerenderRoutes.clear()
|
||||||
for (const path of nuxt.options.nitro.prerender?.routes || []) {
|
|
||||||
routes.add(path)
|
|
||||||
}
|
|
||||||
const processPages = (pages: NuxtPage[], currentPath = '/') => {
|
const processPages = (pages: NuxtPage[], currentPath = '/') => {
|
||||||
for (const page of pages) {
|
for (const page of pages) {
|
||||||
// Skip dynamic paths
|
// Skip dynamic paths
|
||||||
if (page.path.includes(':')) { continue }
|
if (page.path.includes(':')) { continue }
|
||||||
|
const route = joinURL(currentPath, page.path)
|
||||||
const path = joinURL(currentPath, page.path)
|
prerenderRoutes.add(route)
|
||||||
routes.add(path)
|
if (page.children) { processPages(page.children, route) }
|
||||||
if (page.children) { processPages(page.children, path) }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processPages(pages)
|
processPages(pages)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
nuxt.hook('nitro:build:before', (nitro) => {
|
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