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

feat: Add localePrefix for navigation APIs for an improved initial render of Link when using localePrefix: never. Also fix edge case in middleware when using localized pathnames for redirects that remove a locale prefix (fixes an infinite loop). #678

Merged
merged 10 commits into from
Nov 29, 2023

Conversation

amannn
Copy link
Owner

@amannn amannn commented Nov 29, 2023

By accepting an optional localePrefix for the navigation APIs, we can get the initial render of the href of Link right if localePrefix: 'never' is set. This can be helpful if domain-based routing is used and you have a single locale per domain.

Note that this change is backward-compatible. It's now recommended to set the localePrefix for the navigation APIs to get improved behavior for Link in case localePrefix: 'never' is used, but otherwise your app will keep working with the previous behavior.

Ref #444

Copy link

vercel bot commented Nov 29, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2023 4:10pm
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 29, 2023 4:10pm

isLocalHref(href) && locale
? // Potentially the href shouldn't be prefixed, but to determine this we
isLocalHref(href) && (localePrefix !== 'never' || isChangingLocale)
? // For the `localePrefix: 'as-necessary' strategy, the href shouldn't
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
? // For the `localePrefix: 'as-necessary' strategy, the href shouldn't
? // For the `localePrefix: 'as-needed' strategy, the href shouldn't

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks @A7med3bdulBaset!

@amannn amannn changed the title feat: Add localePrefix for navigation APIs feat: Add localePrefix for navigation APIs and fix edge case in middleware when using localized pathnames for redirects that remove a locale prefix Nov 29, 2023
@amannn amannn changed the title feat: Add localePrefix for navigation APIs and fix edge case in middleware when using localized pathnames for redirects that remove a locale prefix feat: Add localePrefix for navigation APIs for an improved initial render of Link when using localePrefix: never. Also fix edge case in middleware when using localized pathnames for redirects that remove a locale prefix Nov 29, 2023
@amannn amannn changed the title feat: Add localePrefix for navigation APIs for an improved initial render of Link when using localePrefix: never. Also fix edge case in middleware when using localized pathnames for redirects that remove a locale prefix feat: Add localePrefix for navigation APIs for an improved initial render of Link when using localePrefix: never. Also fix edge case in middleware when using localized pathnames for redirects that remove a locale prefix (fixes an infinite loop). Nov 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants