amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.37k stars 214 forks source link

`redirect` does not respect `as-needed` locale prefix #1335

Open jorgemoya opened 2 weeks ago

jorgemoya commented 2 weeks ago

Description

When using locale prefix as-needed, I would expect redirect to respect this configuration, instead it will append default locale. This is not how using Link behaves, so it is unexpected. For non default locales, I would expect for redirect to append locale prefix.

Verifications

Mandatory reproduction URL

https://next-intl-redirect-issue-of1rlux37-jorgemoyas-projects.vercel.app/

Reproduction description

Steps to reproduce:

  1. Open reproduction
  2. Click on Click to redirect
  3. Error: Notice how default locale is appended to url. Navigating with header links works as expected.

Expected behaviour

The expected behavior would be to respect the as-needed locale prefix configuration and for navigation within the default locale to ignore appending locale, much like using the Link component. For non default locales it would be fine to append locale prefix.

amannn commented 1 week ago

Thanks for the report! I'm currently working on a re-implementation of the navigation APIs in https://github.com/amannn/next-intl/pull/1316 in order to address some long-standing issues. I think the issue you've reported can be solved too as part of that, I've put this on my list!

This is currently my top priority, I'll keep you updated!