Next.js Discord

Discord Forum

404 Error when using i18n with subpath routing.

Answered
Diamond Master posted this in #help-forum
Open in Discord
Avatar
When i enable i18n in the next js configs, the site redirects me to mysite.eu/locale, but it throws a 404 page and console says it cannot find that url
Answered by Diamond Master
i tried a diff method for i18n and it worked without any problem, idk why the default nextjs one causes problems
View full answer

49 Replies

Avatar
@Diamond Master Click to see attachment
Avatar
your project structure does not include a dynamic folder to receive the locale param. Make sure you add it, for example like that: (see attached)
Image
Avatar
ah, ok, i was suspecting it
wasn't sure tho
lemme try a sec
still the same somehow
Avatar
can you share your folder structure again?
Avatar
Image
Image
Avatar
Your middleware is not correctly configured. You need to move it to the same level as your app/ folder is (not inside)
Avatar
It's empty anyway for now
Avatar
@Diamond Master It's empty anyway for now
Avatar
What happens when you visit "/en/auth/login" ?
Avatar
Gimme a min and i'll try
Avatar
@Diamond Master same error
Avatar
can you provide a repro, for example via github or https://codesandbox.io/ that shows only the error?
Avatar
wdym only shows the error?
Avatar
@Diamond Master wdym only shows the error?
Avatar
that shows the error. I don't want to get your whole code and look through everything, so create a repro that contains only the files/code that is needed to reproduce the error
Avatar
ok, gimme a min
only the files i am using
and that should reproduce the error
Avatar
@Diamond Master <@301376057326567425> https://github.com/Diamantino-Op/VoxelGamesWeb/tree/main
Avatar
Thanks for sharing! Are you it's the same as your current project? The dirs look different...
Image
Image
or well, not rn
Avatar
when you move the lang dir inside the app dir, then it works fine: https://codesandbox.io/p/github/Diamantino-Op/VoxelGamesWeb/csb-pfqmv5/draft/bold-dew
Image
Avatar
wtf
i did that and it didn't work anyway
oh wait, you took everything out of the (frontend) folder
Avatar
@Diamond Master oh wait, you took everything out of the (frontend) folder
Avatar
yea, I might moved something wrong lol. However it shows that the page is working with the dynamic locale param
Avatar
that's strange
why didn't it work for me
i'll try again
Avatar
@Diamond Master why didn't it work for me
Avatar
Yea, your file structure need to be:
/app/[lang]/(frontend)/.../..
Avatar
Image
it's like this atm
and it still throws error 404
Avatar
Your error is currently not reproduceable for me. Either remove the backend folder or move it in the lang as well
Avatar
i'll try to remove the backend
evem without backend still nothing
Avatar
@Diamond Master evem without backend still nothing
Avatar
it looks like your error is not reproducable for me. Provide a reproduction with the folder path /app/[lang]/(frontend)/.../.. and show, that it does not work with that folder structure
Avatar
wait why do you have en as the lang?
it should be en-US
Avatar
@Diamond Master wait why do you have en as the lang?
Avatar
en = language code for english
Avatar
yeah, but i set it as en-US as default
Avatar
@Diamond Master yeah, but i set it as en-US as default
Avatar
yea, there shouldnt be any difference
Avatar
i tried a diff method for i18n and it worked without any problem, idk why the default nextjs one causes problems
Answer
Avatar
thx anyway!