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 support for custom prefixes for i18n routing #1086

Merged
merged 49 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
06c43e2
Add support in middleware
amannn May 23, 2024
477bdda
Fix types
amannn May 23, 2024
0e6dc48
Merge remote-tracking branch 'origin/main' into feat/custom-prefixes
amannn May 23, 2024
67aedf3
First implementation for shared pathnames nav, consolidate redirect i…
amannn May 23, 2024
9a9a896
First tests for localized pathnames
amannn May 23, 2024
446bfc2
More tests, more progress
amannn May 23, 2024
a0a7b8d
Minor perf optimization: Don't pass locales to client when not necessary
amannn May 24, 2024
c6ad80c
Fix initial render when passing a relative href to <Link />
amannn May 24, 2024
bd4eb54
Refactor middleware
amannn May 24, 2024
efb993b
Fix types in middleware tests
amannn May 24, 2024
068bec4
Refactor navigation APIs
amannn May 27, 2024
e7d84d3
Seems to be working?
amannn May 27, 2024
fa97018
Some cleanup
amannn May 27, 2024
e4cd5fe
Some cleanup
amannn May 27, 2024
d4f71f0
Fix lint
amannn May 27, 2024
cbaf908
Clean up receiving config
amannn Jun 3, 2024
301f1dc
Refactor Locales > AppLocales, AllLocales > Locales
amannn Jun 3, 2024
137d22a
Sizes
amannn Jun 3, 2024
c1c0a72
Merge remote-tracking branch 'origin/main' into feat/custom-prefixes
amannn Jun 3, 2024
f3b10df
First draft of docs
amannn Jun 3, 2024
8d9c144
Remove legacy dts file
amannn Jun 3, 2024
13c2953
Export routing, deprecate pathnames in navigation
amannn Jun 3, 2024
b0bf9fb
Revert breaking type
amannn Jun 3, 2024
d533347
Fix build
amannn Jun 3, 2024
acbe01c
Some cleanup
amannn Jun 3, 2024
9589a96
Fix lint
amannn Jun 3, 2024
6f54bfb
Docs fixes, optional locales argument for locale prefix config
amannn Jun 4, 2024
8c6f104
Search optimization
amannn Jun 4, 2024
3dc6b74
e2e tests
amannn Jun 4, 2024
2f7d1bf
Merge branch 'main' into feat/custom-prefixes
amannn Jun 4, 2024
ba51d3b
thanks matt
amannn Jun 4, 2024
3cff3ca
Cleanup
amannn Jun 4, 2024
3403406
More tests and fixes in middleware
amannn Jun 4, 2024
41291ee
Fix lint
amannn Jun 4, 2024
decf4e7
Bump size
amannn Jun 4, 2024
b80b4f2
`LocalePrefixConfig` -> `LocalePrefix`
amannn Jun 4, 2024
3287cba
Simplify example
amannn Jun 4, 2024
aa7619e
Fun with locales
amannn Jun 5, 2024
0cea55d
Shorter extension
amannn Jun 5, 2024
87cdc93
Minor docs fixes
amannn Jun 5, 2024
14aa525
Wording
amannn Jun 5, 2024
cbb78fb
Docs for default locale
amannn Jun 5, 2024
c16db9e
Fix typo
amannn Jun 6, 2024
a66ee32
Move cookie sync to separate file
amannn Jun 6, 2024
d03d79b
Simplify middleware logic slightly
amannn Jun 6, 2024
07ed46b
Remove comment
amannn Jun 6, 2024
5ae5be4
Add test for https://github.com/amannn/next-intl/issues/940
amannn Jun 6, 2024
c32fac0
Merge remote-tracking branch 'origin/main' into feat/custom-prefixes
amannn Jun 10, 2024
2afe828
Fix links
amannn Jun 10, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions docs/pages/blog/next-intl-3-0.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ With 3.0, we're cleaning up these APIs by moving them to a shared namespace as w
+ const {Link, useRouter, usePathname, redirect} = createSharedPathnamesNavigation({locales});
```

Typically, you'll want to call this factory function in a central place in your app where you can easily import from (see [the navigation docs](/docs/routing/navigation#shared-pathnames)).
Typically, you'll want to call this factory function in a central place in your app where you can easily import from (see [the navigation docs](/docs/routing/navigation)).

These changes bring the existing APIs in line with the new [`createLocalizedPathnamesNavigation` API](/docs/routing/navigation#localized-pathnames) that allows you to localize pathnames:
These changes bring the existing APIs in line with the new [`createLocalizedPathnamesNavigation` API](/docs/routing/navigation) that allows you to localize pathnames:

```tsx filename="navigation.ts"
import {createLocalizedPathnamesNavigation, Pathnames} from 'next-intl/navigation';
Expand Down Expand Up @@ -84,14 +84,14 @@ By using a similar API, you can upgrade from shared pathnames to localized pathn

### Switching the middleware default of `localePrefix` to `always`

Previously, the [`localePrefix` of the middleware](/docs/routing/middleware#locale-prefix) defaulted to `as-needed`, meaning that a locale prefix was only added for non-default locales.
Previously, the [`localePrefix` of the middleware](/docs/routing#locale-prefix) defaulted to `as-needed`, meaning that a locale prefix was only added for non-default locales.

This default has now been changed to `always` since this has two advantages:

1. We can recommend [a safer default `matcher`](/docs/routing/middleware#matcher-config) that needs no extra treatment for pathnames with dots (e.g. `/users/jane.doe`)
2. It avoids an [edge case of `Link`](/docs/routing/middleware#locale-prefix-as-needed) where we include a prefix for the default locale on the server side but patch this on the client side by removing the prefix (certain SEO tools might report a hint that a link points to a redirect in this case).
2. It avoids an [edge case of `Link`](/docs/routing#locale-prefix-as-needed) where we include a prefix for the default locale on the server side but patch this on the client side by removing the prefix (certain SEO tools might report a hint that a link points to a redirect in this case).

If you want to stay on the `as-needed` strategy, you can [configure this option](/docs/routing/middleware#locale-prefix-as-needed) in the middleware.
If you want to stay on the `as-needed` strategy, you can [configure this option](/docs/routing#locale-prefix-as-needed) in the middleware.

### Static rendering of Server Components

Expand Down
8 changes: 4 additions & 4 deletions docs/pages/docs/environments/metadata-route-handlers.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ Next.js supports providing alternate URLs per language via the [`alternates` ent
<Tabs items={['Shared pathnames', 'Localized pathnames']}>
<Tab>

If you're using [shared pathnames](/docs/routing/navigation#shared-pathnames), you can iterate over an array of pathnames that your app supports and generate a sitemap entry for each pathname.
If you're use the same pathnames for all locales (i.e. you're not using the [`pathnames`](/docs/routing#pathnames) setting), you can iterate over an array of pathnames that your app supports and generate a sitemap entry for each pathname.

**Example:**

Expand Down Expand Up @@ -121,7 +121,7 @@ export default function sitemap(): MetadataRoute.Sitemap {
</Tab>
<Tab>

If you're using [localized pathnames](/docs/routing/navigation#localized-pathnames), you can use the keys of your already declared `pathnames` and generate an entry for each locale via the [`getPathname`](/docs/routing/navigation#getpathname) function.
If you're using the [`pathnames`](/docs/routing#pathnames) setting, you can use the keys of your already declared `pathnames` and generate an entry for each locale via the [`getPathname`](/docs/routing/navigation#getpathname) function.

```tsx
import {MetadataRoute} from 'next';
Expand Down Expand Up @@ -159,8 +159,8 @@ export default function sitemap(): MetadataRoute.Sitemap {
<Callout>
Note that your implementation may vary depending on your routing configuration
(e.g. if you're using a
[`localePrefix`](/docs/routing/middleware#locale-prefix) other than `always`
or [locale-specific domains](/docs/routing/middleware#domain-based-routing)).
[`localePrefix`](/docs/routing#locale-prefix) other than `always`
or [locale-specific domains](/docs/routing#domains)).
</Callout>

### Route Handlers
Expand Down
Loading
Loading