mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): always prerender at least one page with crawler (#28131)
This commit is contained in:
parent
694229071b
commit
082a6f78ba
@ -148,6 +148,12 @@ export default defineNuxtModule({
|
|||||||
priority: 10, // built-in that we do not expect the user to override
|
priority: 10, // built-in that we do not expect the user to override
|
||||||
filePath: resolve(distDir, 'pages/runtime/page-placeholder'),
|
filePath: resolve(distDir, 'pages/runtime/page-placeholder'),
|
||||||
})
|
})
|
||||||
|
// Prerender index if pages integration is not enabled
|
||||||
|
nuxt.hook('nitro:init', (nitro) => {
|
||||||
|
if (nuxt.options.dev || !nuxt.options.ssr || !nitro.options.static || !nitro.options.prerender.crawlLinks) { return }
|
||||||
|
|
||||||
|
nitro.options.prerender.routes.push('/')
|
||||||
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -309,28 +315,22 @@ export default defineNuxtModule({
|
|||||||
processPages(pages)
|
processPages(pages)
|
||||||
})
|
})
|
||||||
|
|
||||||
// For static sites with ssr: false with crawl, prerender all routes
|
nuxt.hook('nitro:build:before', (nitro) => {
|
||||||
nuxt.hook('nitro:init', (nitro) => {
|
|
||||||
if (nuxt.options.dev || !nitro.options.static || nuxt.options.router.options.hashMode || !nitro.options.prerender.crawlLinks) { return }
|
if (nuxt.options.dev || !nitro.options.static || nuxt.options.router.options.hashMode || !nitro.options.prerender.crawlLinks) { return }
|
||||||
|
|
||||||
// Only hint the first route when `ssr: true` and no routes are provided
|
// Only hint the first route when `ssr: true` and no routes are provided
|
||||||
|
// as the rest will be injected at runtime when this is prerendered
|
||||||
if (nuxt.options.ssr) {
|
if (nuxt.options.ssr) {
|
||||||
nitro.hooks.hook('prerender:routes', (routes) => {
|
const [firstPage] = [...prerenderRoutes].sort()
|
||||||
if ([...routes].every(r => r.match(/(^\/api|\.\w+)/))) {
|
nitro.options.prerender.routes.push(firstPage || '/')
|
||||||
const [firstPage] = [...prerenderRoutes].sort()
|
|
||||||
routes.add(firstPage || '/')
|
|
||||||
}
|
|
||||||
})
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prerender all non-dynamic page routes when generating `ssr: false` app
|
// Prerender all non-dynamic page routes when generating `ssr: false` app
|
||||||
nuxt.hook('nitro:build:before', (nitro) => {
|
for (const route of nitro.options.prerender.routes || []) {
|
||||||
for (const route of nitro.options.prerender.routes || []) {
|
prerenderRoutes.add(route)
|
||||||
prerenderRoutes.add(route)
|
}
|
||||||
}
|
nitro.options.prerender.routes = Array.from(prerenderRoutes)
|
||||||
nitro.options.prerender.routes = Array.from(prerenderRoutes)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
nuxt.hook('imports:extend', (imports) => {
|
nuxt.hook('imports:extend', (imports) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user