-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Middleware doesn't redirect and serves 404 when a page doesn't exist #8226
Comments
I am looking into this. Here's a couple of questions:
|
Here is my use case. Now, I could create a
Let me know if I could provide more info on this. And really appreciate your quick reply on this @ematipico! Cheers. |
I have been talking with @matthewp about this, and we agree that it makes sense for users to have a middleware called when pages don't exist (the default 404 doesn't exist on disk). However, another discussion was going on where this could cause inconsistencies among adapters. We might be able to support these cases - as mentioned by @lilnasy - where if an adapter doesn't call our |
Is it possible for you to create an empty index.astro? The idea is that it will never be used but it will cause the middleware be run. |
Also, I think there's some nuance to our "default" 404 page — it's not so much a default as it is a backup which is only used in certain cases. |
Myself and @matthewp had a chat about it. We agreed that this is not a bug because Astro behaves by design: render matched routes (URL route must match the route on disk). We think this is a feature because it will enhance Astro's behaviour by allowing it to attempt to render routes that aren't matched. This is a new use case that we hadn't considered, and it's worth implementing. Implementing this feature will have some side effects in serverless environments if the user uses We will work on implementing this new feature after 3.0 release. |
I am going ahead and close the issue. This is a feature, and it requires some internal changes, which should also be reflected in the respective adapters. One of our maintainers - @lilnasy - created a proposal that would solve this issue: withastro/roadmap#681 If you need it, please upvote it! |
Astro info
What browser are you using?
Firefox, Chrome
Describe the Bug
This is the same issue in #7752, released in #7851 #7854, but the issue isn't fixed.
I am trying to redirect
/
(which does not exist) to the localized content (/en
or/zh
etc), but Astro returns 404 instead of running the middleware.The bug is reproduced at the link below.
What's the expected result?
Middleware should run before Astro returns 404.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-stgbcz?file=src%2Fmiddleware.js
Participation
The text was updated successfully, but these errors were encountered: