Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 404: dynamic 404.astro route to render "not found" page #180

Merged
merged 6 commits into from
Sep 20, 2024

Conversation

jbmoelker
Copy link
Member

@jbmoelker jbmoelker commented Sep 17, 2024

Changes

Updating @astrojs/cloudflare to v10 in #154 appears to have broken Cloudflare's built-in behaviour to return the closest 404.html in case a page is not found.

This PR solves this issue by replacing Cloudflare's behaviour with Astro's Custom 404 Page Behaviour using a dynamic src/pages/404.astro (prerender = false) so that it has access to the request object and can match the locale during runtime.

Associated issue

Resolves #161
Resolves #135

How to test

Test different pages that don't exist and see that it returns the Not Found page with the closest locale and with a 404 status:

/nl/aapje → Niet gevonden (404)
/en/aapje → Not Found (404)
/de/aapje → Not Found (404)
/aapje → Not Found (404)

Checklist

  • I have performed a self-review of my own code
  • I have made sure that my PR is easy to review (not too big, includes comments)
  • I have made updated relevant documentation files (in project README, docs/, etc)
  • I have added a decision log entry if the change affects the architecture or changes a significant technology
  • I have notified a reviewer

Copy link

cloudflare-workers-and-pages bot commented Sep 20, 2024

Deploying head-start with  Cloudflare Pages  Cloudflare Pages

Latest commit: de0c8ae
Status: ✅  Deploy successful!
Preview URL: https://5b7e51f9.head-start.pages.dev
Branch Preview URL: https://fix-404-dynamic-route.head-start.pages.dev

View logs

@jbmoelker jbmoelker marked this pull request as ready for review September 20, 2024 14:37
@jbmoelker jbmoelker merged commit 90cdb33 into main Sep 20, 2024
5 checks passed
@jbmoelker jbmoelker deleted the fix/404-dynamic-route branch September 20, 2024 14:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom 404 page no longer working 404 page not working in dev mode
3 participants