Default route not working with rewrites/redirects and i18next
Unanswered
Saarloos Wolfdog posted this in #help-forum
Saarloos WolfdogOP
eg.
while
with
Disabling locale with
How can we get both working?
domain.com/en-US/test WORKSwhile
domain.com/test NO WORK (404)with
rewrites: () => {
return {
beforeFiles: [
{
source: '/test',
destination: `https://jsonplaceholder.typicode.com/posts/1`,
},
],
},
}Disabling locale with
locale: false fixes the default route but then breaks all locale routes to that rewrite.How can we get both working?
14 Replies
Saarloos WolfdogOP
Are you using domain-based i18n or path-based?
Also, have you tried doing it in a
You might also be able to do
return instead of beforeFIles?You might also be able to do
rewrites: () => {
return {
beforeFiles: [
{
source: '/:locale/test',
destination: `https://jsonplaceholder.typicode.com/posts/1`,
},
],
},
}Saarloos WolfdogOP
@Marchy you can have a peak at the reproduction examples in the issue mentioned above https://github.com/vercel/next.js/issues/57616
it doesn't use beforeFiles and is just using the official nextjs example for i18n
it doesn't use beforeFiles and is just using the official nextjs example for i18n
@Saarloos Wolfdog <@203709756689350656> you can have a peak at the reproduction examples in the issue mentioned above https://github.com/vercel/next.js/issues/57616
it doesn't use beforeFiles and is just using the official nextjs example for i18n
Changing your source to
/:locale/test should resolve thisSaarloos WolfdogOP
@Marchy Can you reread that issue? We strictly do not want to use locale in this rewrite.
browse to
we explicitly do not want
browse to
/test should resolve to https://jsonplaceholder.typicode.com/posts/1we explicitly do not want
/:locale/test to do anything. These should 404.@Saarloos Wolfdog <@203709756689350656> Can you reread that issue? We strictly do not want to use locale in this rewrite.
browse to `/test` should resolve to `https://jsonplaceholder.typicode.com/posts/1`
we explicitly do not want `/:locale/test` to do anything. These should 404.
Could you please do this in a reproduction repo instead of forking next.js? It's a huge download.
Saarloos WolfdogOP
If your developing / supporting NextJS then the repo examples are usually the most sought after for reproduction repos. It's literally how the test cases are run. Nw, I think the issue is on their radar.
@Saarloos Wolfdog If your developing / supporting NextJS then the repo examples are usually the most sought after for reproduction repos. It's literally how the test cases are run. Nw, I think the issue is on their radar.
I don't believe this is an error within Next.js. You might just need to do something like
rewrites: () => {
return {
beforeFiles: [
{
source: '/:locale/test',
destination: `/test`,
},
{
source: '/test',
destination: `https://jsonplaceholder.typicode.com/posts/1`,
},
],
},
}Saarloos WolfdogOP
@Marchy and what would be the result if then someone browsed to
https://nextjs-forum.com/post/1167473900519694386#message-1167650017385918474
/en_US/test1?https://nextjs-forum.com/post/1167473900519694386#message-1167650017385918474
@Saarloos Wolfdog <@203709756689350656> and what would be the result if then someone browsed to `/en_US/test1`?
https://discord.com/channels/752553802359505017/1167473900519694386/1167650017385918474
locale: false fixes the default route but then breaks all locale routes to that rewrite.
What did you mean by this?
Saarloos WolfdogOP
Thanks for trying to help @Marchy . I think you may only have read what I wrote in the above post in discord but have yet to read the explicit github issue that I also posted. It is very detailed and completely lays out what the problem is. https://github.com/vercel/next.js/issues/57616