Why does i18n docs/example use middleware while next config js redirect is easier? Is it deprecated?
Answered
Havana posted this in #help-forum
HavanaOP
You can see, adding i18n support for redirects is very easy here: https://nextjs.org/docs/14/app/api-reference/next-config-js/redirects#redirects-with-i18n-support
But when you read the official i18n nextjs doc, you see that what i18n support in the next.config.js does very easily, in middleware it gets done with manual code, in the official docs PLUS example:
- https://nextjs.org/docs/14/app/building-your-application/routing/internationalization
- https://github.com/vercel/next.js/blob/canary/examples/app-dir-i18n-routing/middleware.ts
Is next.config.js deprecated? Just dont see why official examples use manual boilerplate i18n code in middleware, why next config js rewrite has very plug and play i18n support.
But when you read the official i18n nextjs doc, you see that what i18n support in the next.config.js does very easily, in middleware it gets done with manual code, in the official docs PLUS example:
- https://nextjs.org/docs/14/app/building-your-application/routing/internationalization
- https://github.com/vercel/next.js/blob/canary/examples/app-dir-i18n-routing/middleware.ts
Is next.config.js deprecated? Just dont see why official examples use manual boilerplate i18n code in middleware, why next config js rewrite has very plug and play i18n support.
Answered by B33fb0n3
iirc both ways are correct and both can be used. I would use the redirect when I just want to build something very fast. On the other side I would use the middleware option, when I want to be flexible with my code. At the end you know your project the best and you should decide what suites best
6 Replies
@Havana You can see, adding i18n support for redirects is very easy here: https://nextjs.org/docs/14/app/api-reference/next-config-js/redirects#redirects-with-i18n-support
But when you read the official i18n nextjs doc, you see that what i18n support in the next.config.js does very easily, in middleware it gets done with manual code, in the official docs PLUS example:
- https://nextjs.org/docs/14/app/building-your-application/routing/internationalization
- https://github.com/vercel/next.js/blob/canary/examples/app-dir-i18n-routing/middleware.ts
Is next.config.js deprecated? Just dont see why official examples use manual boilerplate i18n code in middleware, why next config js rewrite has very plug and play i18n support.
iirc both ways are correct and both can be used. I would use the redirect when I just want to build something very fast. On the other side I would use the middleware option, when I want to be flexible with my code. At the end you know your project the best and you should decide what suites best
Answer
@B33fb0n3 iirc both ways are correct and both can be used. I would use the redirect when I just want to build something very fast. On the other side I would use the middleware option, when I want to be flexible with my code. At the end you know your project the best and you should decide what suites best
HavanaOP
Thanks. Yeah i realized what the one in middleware does, cant be done with next config js: using user's preferred browser locale etc.
Btw, what is the order of execution that nextjs uses? nextconfigjs redirect then middleware, or first middleware?
Btw, what is the order of execution that nextjs uses? nextconfigjs redirect then middleware, or first middleware?
@Havana Thanks. Yeah i realized what the one in middleware does, cant be done with next config js: using user's preferred browser locale etc.
Btw, what is the order of execution that nextjs uses? nextconfigjs redirect then middleware, or first middleware?
it should execute the nextjs config first, because when you have an external image it will run though the nextjs config and checks if it's allowed there and if not it will be denied. So nextconfig should be executed before the middleware
@Havana solved?
HavanaOP
Thx
that's not the answer. I marked the correct one. You don't need to do anything else.