Next.js: [9.5.6-canary.9][i18n] next/link does not handle cross-locale links correctly

Created on 21 Oct 2020  路  8Comments  路  Source: vercel/next.js

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

Most helpful comment

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

All 8 comments

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">

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 馃槖

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

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.

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.

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?

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?

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

wagerfield picture wagerfield  路  3Comments

timneutkens picture timneutkens  路  3Comments

formula349 picture formula349  路  3Comments

jesselee34 picture jesselee34  路  3Comments

kenji4569 picture kenji4569  路  3Comments