content icon indicating copy to clipboard operation
content copied to clipboard

redirect does not work on a static

Open gitFoxCode opened this issue 3 years ago • 10 comments

Environment



Reproduction

  1. npx nuxi init content-app -t content
  2. documentDriven: true
  3. create any .md file with:
---
redirect: 'https://google.pl/'
---
  1. npm run generate
  2. npm 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

gitFoxCode avatar Dec 19 '22 12:12 gitFoxCode

I thinks it's because redirect must be server side. So, depending of your deployment environment, you could try a _redirect file.

Barbapapazes avatar Dec 21 '22 10:12 Barbapapazes

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.

Barbapapazes avatar Dec 21 '22 10:12 Barbapapazes

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 avatar Dec 21 '22 12:12 farnabaz

@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

gitFoxCode avatar Dec 21 '22 13:12 gitFoxCode

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 avatar Dec 21 '22 13:12 farnabaz

@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

gitFoxCode avatar Dec 21 '22 20:12 gitFoxCode

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?

farnabaz avatar Dec 23 '22 15:12 farnabaz

Any information about this? Redirects still not working on latest version

gitFoxCode avatar Feb 15 '23 10:02 gitFoxCode

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.

github-actions[bot] avatar Feb 07 '25 11:02 github-actions[bot]

Issue still occurs

mrGrochowski avatar Dec 08 '25 08:12 mrGrochowski