Skip to content
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

[9.5.6-canary.9][i18n] next/link does not handle cross-locale links correctly #18086

Closed
rokinsky opened this issue Oct 21, 2020 · 9 comments
Closed

Comments

@rokinsky
Copy link
Contributor

Bug report

Describe the bug

I'm trying to use the experimental i18n feature (#17078) and it seems like next/link does not handle cross-locale links correctly.

To Reproduce

Repository: next.js-bug-link-locale
Steps to reproduce the behavior:

  1. Go to http://localhost:3000/nl-nl/42
  2. Click on 'TO /de-de/42' link
  3. See 404 error and URL http://localhost:3000/nl-nl/de-de/42

Expected behavior

Visiting http://localhost:3000/de-de/42 without errors

Screenshots

Screenshot 2020-10-21 at 14 44 22

Screenshot 2020-10-21 at 14 47 43

System information

  • OS: macOS
  • Browser (if applies): chrome
  • Version of Next.js: 9.5.6-canary.9
  • Version of Node.js: 10.22.1

Additional context

N/A

@timneutkens
Copy link
Member

We changed the behavior a bit from the RFC as it turned out that linking around using just the path has issues. You can use <Link href="/42" locale="de-de">

@rokinsky
Copy link
Contributor Author

Thanks for explaining @timneutkens. This solution doesn't sound good to me because I receive full slugs from a CMS including locale in the path already, like /de-de/hello/world, so the RFC becomes less attractive 😒

@timneutkens
Copy link
Member

Will discuss with the team and see what we can do for this use case 🙏

@ljosberinn
Copy link
Contributor

Would you mind sharing a bit more info on the issues that came up? My solution just prepends the locale automatically, but there are no underlying changes made in Next in my case. Autoprepending has been very convenient though so I'd love to see this.

@timneutkens
Copy link
Member

We're currently discussing adding <Link locale={false}> for the case @rokinsky is showing. So you'd have to <Link locale={false} href="/de-de/hello/world"> and we won't do automatic locale prepending. Would that work for you?

@ljosberinn say you have a locale set up like de and a pages/de.js, you would not be able to link to pages/de.js given that the locale would be matched. There's a few more cases @Janpot showed, maybe he can post them here. It's a similar issue to basePath basically.

@Janpot
Copy link
Contributor

Janpot commented Oct 21, 2020

Yes, one case would be when you have a page that has the same name as a locale.
Another case would be with dynamic routes, say you have a ./pages/index.js and ./pages/[var].js, what should /de link to? Or say you have optional catch all ./pages/[[...path]].js, what will the path parameter be? Will it contain 'de' as the first element?

@rokinsky
Copy link
Contributor Author

We're currently discussing adding <Link locale={false}> for the case @rokinsky is showing. So you'd have to <Link locale={false} href="/de-de/hello/world"> and we won't do automatic locale prepending. Would that work for you?

Yes, that works for me. Thank you. Will the same behavior be performed using { locale: false } in next/router options?

@timneutkens
Copy link
Member

timneutkens commented Oct 21, 2020

@rokinsky yeah locale is available already in the options object you can pass in router.push and router.replace 👍

@balazsorban44
Copy link
Member

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@vercel vercel locked as resolved and limited conversation to collaborators Jan 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants