feat: Add defineRouting
for easier i18n routing setup
#1299
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
defineRouting
API that returns arouting
object that can be used to initialize the middleware as well as the navigation APIs. This provides type-safety for your i18n config with a single import and helps to ensure that your i18n config is in sync across your app.While this change is purely additional, it's encouraged to adopt
defineRouting
in existing code bases and the docs have been updated to reflect this.Migration example: amannn/next-intl-bug-repro-app-router@0a00684
In case you're providing either
alternateLinks
orlocaleDetection
tocreateMiddleware
, these options can now be passed as a second argument:Changes
defineRouting
APIrouting
) as second param tocreateMiddleware
src/routing.ts
instead ofsrc/navigation.ts
i18n.ts
in getting started docs