-
-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add
defineRouting
for easier i18n routing setup (#1294)
**Summary** Adds a new [`defineRouting`](https://next-intl-docs-git-feat-v4-routing-next-intl.vercel.app/docs/routing#define-routing) API that returns a `routing` 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. ```tsx // routing.ts import {defineRouting} from 'next-intl/routing'; export const routing = defineRouting({ locales: ['en-US', 'en-GB'], defaultLocale: 'en-US', localePrefix: { mode: 'always', prefixes: { 'en-US': '/us', 'en-GB': '/uk' } }, pathnames: { '/': '/', '/organization': { 'en-US': '/organization', 'en-GB': '/organisation' } } }); ``` ```tsx // middleware.ts import createMiddleware from 'next-intl/middleware'; import {routing} from './routing'; export default createMiddleware(routing); export const config = { // Match only internationalized pathnames matcher: ['/', '/(de|en)/:path*'] }; ``` ```tsx // navigation.ts import {createSharedPathnamesNavigation} from 'next-intl/navigation'; import {routing} from './routing'; export const {Link, redirect, usePathname, useRouter} = createSharedPathnamesNavigation(routing); ``` (in the docs we now suggest to create navigation APIs directly in `routing.ts`) **Changes** - feat: Add `defineRouting` API - feat: Allow to pass middleware options (ie. now everything that is not `routing`) as second param to `createMiddleware` - docs: Suggest using `src/routing.ts` instead of `src/navigation.ts` - docs: Suggest setting up navigation APIs in getting started docs - docs: Suggest setting up middleware before `i18n.ts` in getting started docs **TODO:** - [ ] More testing (via a prerelease) - [ ] Update bug repro app router (after release) --------- Co-authored-by: amannn <amannn@users.noreply.github.com>
- Loading branch information
Showing
73 changed files
with
998 additions
and
809 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
{ | ||
"getting-started": "Getting started", | ||
"usage": "Usage guide", | ||
"environments": "Environments", | ||
"routing": "Routing", | ||
"environments": "Environments", | ||
"workflows": "Workflows & integrations", | ||
"design-principles": "Design principles" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.