diff --git a/src/prerender.ts b/src/prerender.ts index 7c16167c..aeab6a2c 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -43,6 +43,8 @@ export function isNuxtGenerate(nuxt: Nuxt = useNuxt()) { ].includes(resolveNitroPreset()) } +const NuxtRedirectHtmlRegex = /
<\/head><\/html>/ + export function setupPrerenderHandler(_options: { runtimeConfig: ModuleRuntimeConfig, logger: ConsolaInstance }, nuxt: Nuxt = useNuxt()) { const { runtimeConfig: options, logger } = _options const prerenderedRoutes = (nuxt.options.nitro.prerender?.routes || []) as string[] @@ -64,6 +66,10 @@ export function setupPrerenderHandler(_options: { runtimeConfig: ModuleRuntimeCo // extract alternatives from the html if (!route.fileName?.endsWith('.html') || !html || ['/200.html', '/404.html'].includes(route.route)) return + // ignore redirects + if (html.match(NuxtRedirectHtmlRegex)) { + return + } // maybe the user already provided a _sitemap on the route route._sitemap = defu(route._sitemap, { diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 461c3159..8b608838 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -8,6 +8,11 @@ export default defineNuxtConfig({ site: { url: 'https://nuxtseo.com', }, + routeRules: { + '/foo-redirect': { + redirect: '/foo', + }, + }, debug: process.env.NODE_ENV === 'test', sitemap: { autoLastmod: false, diff --git a/test/fixtures/basic/pages/index.vue b/test/fixtures/basic/pages/index.vue index 0a5a34a2..16acd803 100644 --- a/test/fixtures/basic/pages/index.vue +++ b/test/fixtures/basic/pages/index.vue @@ -4,6 +4,9 @@