-
Notifications
You must be signed in to change notification settings - Fork 27k
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
Next internationalized routing allows multiple locales in url path #31420
Comments
possible duplicate of #31228, which should be fixed in v12.0.4-canary.5 - can you try with the latest canary version? |
Thanks for the quick answer! 12.0.4-canary.5 seems to fix part of the problem (as described in the issue you mentioned)! However when I use a slug like |
Not fixed in 12.0.4. I can still access http://localhost:3000/en/en or http://localhost:3000/en/de etc. as described in #31228 and #20120 |
I think there must be an error message. Next will redirect from I don’t know which solution would be correct here. If you have some ideas, it will be interesting for me to try to implement them. But now - in the root pages directory the pages should return an error (404) for dynamic routes with locales as slug. Maybe good solution here is redirect to homepage, but to which locale - first or last? If you use getStatisProps or gerServerSideProps, you can add this code for disabling this pages:
for redirect to home page:
Before my fix at: |
Also for redirects you can add the following code to next.config.js:
But it will redirect twice for default locales: |
That's my fix at the moment too, easiest to write a quick redirect in
This is just a temp fix until it's fixed in the framework (been waiting for a year now...). Correct behaviour should be 404. |
Probably related to #21210 |
Hello, is any update on this topic with the latest nextjs version? |
What version of Next.js are you using?
11.0.1 and 12.0.0
What version of Node.js are you using?
14.18.1
What browser are you using?
Firefox, Chrome
What operating system are you using?
macOS
How are you deploying your application?
next dev
Describe the Bug
When adding internationalized routing to a Next.js app, multiple subpaths redirect to the same route.
If for example I use the "en" locale as the defaultLocale, the following urls route to the same index page:
http://localhost:3000
http://localhost:3000/en
http://localhost:3000/en/en
http://localhost:3000/[anyOtherLocaleInNextConfig]/en
The router object for the
http://localhost:3000/en/en
option looks similar to this:{ "pathname": "/", "route": "/", "query": {}, "asPath": "/en", "components": { "/": { "initial": true, "props": { "pageProps": {} } }, "/_app": { "styleSheets": [] } }, "isFallback": false, "basePath": "", "locale": "en", "locales": [ "de", "en", "us" ], "defaultLocale": "en", "isReady": true, "isPreview": false, "isLocaleDomain": false, "events": {} }
This causes problems when using slugs like
http://localhost:3000/locale/[:slug]
because the second/en
in thehttp://localhost:3000/en/en
url doesn't get detected as a slug. However using any string other than a locale defined in thenext.config.js
works just fine.I hope this description is comprehensible - I've been banging my head against my desk for the past few days and might have lost one or two braincells.
Expected Behavior
When using slugs like
http://localhost:3000/locale/[:slug]
, the second/en
inlocalhost:3000/en/en
should be detected as the slug.To Reproduce
yarn create next-app --typescript
next.config.js
:i18n: { defaultLocale: "en", locales: ["en", "de", "us"] },
yarn dev
http://localhost:3000/en/en
,http://localhost:3000/en
,http://localhost:3000
and see the exact same page[slug]
to the pages folder and create an index file in the[slug]
folderhttp://localhost:3000/en/test
but not usinghttp://localhost:3000/en/en
,http://localhost:3000/en/de
orhttp://localhost:3000/en/us
http://localhost:3000/en/en/test
which then redirects to justhttp://localhost:3000/en/test
The text was updated successfully, but these errors were encountered: