redirect does not work on a static
Environment
- Operating System:
Windows_NT - Node Version:
v18.10.0 - Nuxt Version:
3.0.0 - Nitro Version:
1.0.0 - Package Manager:
[email protected] - Builder:
vite - User Config:
modules,content - Runtime Modules:
@nuxt/[email protected],@nuxtjs/[email protected] - Build Modules:
-
Reproduction
npx nuxi init content-app -t contentdocumentDriven: true- create any .md file with:
---
redirect: 'https://google.pl/'
---
npm run generatenpm run preview
Describe the bug
Redirect does not work after generating a static page, the page autmatically displays 404.
Additional context
No response
Logs
No response
I thinks it's because redirect must be server side. So, depending of your deployment environment, you could try a _redirect file.
Here your response
https://github.com/nuxt/content/blob/main/src/runtime/composables/navigation.ts#L50
So, google.pl is not a URL from your project so no redirection is possible.
Did you remove pages/[...slug].vue after enabling documentDriven? If you don't remove [...slug].vue, enabling documentDriven is pointless because all routes will handle by this page and not by documentDriven's page.
I thinks it's because redirect must be server side
@Barbapapazes The redirection could happen on both sides. On SSG it will happen on client-side. The issue here is that page does not rendered by documentDriven. So redirect value didn't handled at all.
@farnabaz Without [...slug].vue the 404 error is the same due to nuxt-content not finding "google" in 'content', can nuxt-content just detect that if the link starts with http/https it runs a simple window.location? Especially since something like that happens when the SSR is activated. Such a big difference when it could work equally
External link should already handle by document-driven. see:
https://github.com/nuxt/content/blob/6f0c622d5dc5d5d243919b8bea54e1dd5faf45a1/src/runtime/plugins/documentDriven.ts#L256-L262
Do you mind proving the reproduction you've created using stackblitz starter?
@farnabaz https://stackblitz.com/edit/github-7erfxk?file=nuxt.config.ts
npm run dev
Go to /about, everything works fine,
npm run generate
npm run preview
Go to /about, 404 error
Thanks for reproduction, It seems that nitro's prerenderer does not process x-nitro-prerender header for redirected pages.
@pi0 I think Nitro should allow redirected routes to use this header, WDYT?
Any information about this? Redirects still not working on latest version
This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.
Issue still occurs