-
-
Notifications
You must be signed in to change notification settings - Fork 245
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
Using a custom middleware instead of the supplied #609
Comments
Thank you very much for this detailed feature request! I agree there's a piece missing here currently. I've opened #653 to collect this issue together with similar ones, also to share solutions that can be used today.
That's a good point. I've addressed this in #654.
The header will definitely remain there for at least the 3.x version range. If anything changes in regard to it, this will be announced as part of a major version. |
I'll close this now in favor of #653. This issue is mentioned there and will be taken care of. |
Is your feature request related to a problem? Please describe.
The default middleware has some limitations to what can be configured. It would be good to have an official way to skip the supplied middleware and write a custom one.
I'm currently on
[email protected]
and[email protected]
when writing this.Some of the issues i've discovered with the official middleware:
Multi-domain with english on all domains can not use "en" as path prefix. Let's say that we have 2 domains with a total of 4 locales: sv-se, en-se, nb-no and en-no.
Turning off locale redirects. Using the same example as above:
Impossible to set a default locale based on domain for paths inside _next/ as these are not recommended to be handled by the middleware. This is possible using a custom middleware.
There are issues with basePath that the middleware shouldn't have to care for if redirects can be completely disabled.
Describe the solution you'd like
Some official way to set the next-intl locale in a custom middleware. Maybe something like
setRequestLocale(request: NextRequest)
.If cookies would be set that should be an option as cookies are not always a requirement for the implementation.
Describe alternatives you've considered
I've currently implemented a middleware that works like what i described above. However, the header to set the locale is not exposed so it feels a bit unstable and requires testing for every update.
If anyones interested heres the full middleware (that works with or without basePath set in next.config):
Usage:
This will totally break the next-intl
<Link>
component. I've created a custom Link component that creates absolute url's including the domain for locales not included in the current domain. But that's a different feature request :)Many thanks for a great library!
The text was updated successfully, but these errors were encountered: