Skip to content

Commit ca02e3d

Browse files
committed
docs: Better searchable headlines
1 parent 132ce52 commit ca02e3d

File tree

2 files changed

+23
-28
lines changed

2 files changed

+23
-28
lines changed

docs/src/pages/docs/routing.mdx

+19-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Card from '@/components/Card';
33
import Cards from '@/components/Cards';
44
import Callout from '@/components/Callout';
55

6-
# Next.js internationalized routing
6+
# Routing
77

88
<Callout>
99
Routing APIs are only needed when you're using [i18n
@@ -17,7 +17,7 @@ import Callout from '@/components/Callout';
1717

1818
This enables you to express your app in terms of APIs like `<Link href="/about">`, while aspects like the locale and user-facing pathnames are automatically handled behind the scenes (e.g. `/de/ueber-uns`).
1919

20-
## Define routing
20+
## `defineRouting`
2121

2222
The routing configuration that is shared between the [middleware](/docs/routing/middleware) and [the navigation APIs](/docs/routing/navigation) can be defined with the `defineRouting` function.
2323

@@ -46,11 +46,11 @@ Still, in case you're defining other routing config, make sure to keep them in s
4646

4747
</Details>
4848

49-
### Locale prefix
49+
### `localePrefix`
5050

5151
By default, the pathnames of your app will be available under a prefix that matches your directory structure (e.g. `/en/about``app/[locale]/about/page.tsx`). You can however adapt the routing to optionally remove the prefix or customize it per locale by configuring the `localePrefix` setting.
5252

53-
#### Always use a locale prefix (default) [#locale-prefix-always]
53+
#### `localePrefix: 'always'` (default) [#locale-prefix-always]
5454

5555
By default, pathnames always start with the locale (e.g. `/en/about`).
5656

@@ -63,7 +63,7 @@ export const routing = defineRouting({
6363
});
6464
```
6565

66-
#### Don't use a locale prefix for the default locale [#locale-prefix-as-needed]
66+
#### `localePrefix: 'as-needed'` [#locale-prefix-as-needed]
6767

6868
If you want to use no prefix for the default locale (e.g. `/about`), you can configure your routing accordingly:
6969

@@ -81,7 +81,7 @@ export const routing = defineRouting({
8181
1. If you use this routing strategy, make sure that your [middleware matcher](/docs/routing/middleware#matcher-config) detects unprefixed pathnames.
8282
2. If a superfluous locale prefix like `/en/about` is requested, the middleware will automatically redirect to the unprefixed version `/about`. This can be helpful in case you're redirecting from another locale and you want to update a potential cookie value first (e.g. [`<Link />`](/docs/routing/navigation#link) relies on this mechanism).
8383

84-
#### Never use a locale prefix [#locale-prefix-never]
84+
#### `localePrefix: 'never'` [#locale-prefix-never]
8585

8686
If you'd like to provide a locale to `next-intl`, e.g. based on user settings, you can consider setting up `next-intl` [without i18n routing](/docs/getting-started/app-router/without-i18n-routing). This way, you don't need to use the routing integration in the first place.
8787

@@ -158,7 +158,7 @@ If you'd like to encode custom information in the locale, you can use arbitrary
158158

159159
</Details>
160160

161-
### Localized pathnames [#pathnames]
161+
### `pathnames` [#pathnames]
162162

163163
Many apps choose to localize pathnames, especially when search engine optimization is relevant, e.g.:
164164

@@ -312,7 +312,7 @@ Furthermore, in case you provide a locale switcher, it might require special car
312312

313313
</Details>
314314

315-
### Domains
315+
### `domains`
316316

317317
If you want to serve your localized content based on different domains, you can provide a list of mappings between domains and locales via the `domains` setting.
318318

@@ -421,7 +421,7 @@ export const routing = defineRouting({
421421

422422
</Details>
423423

424-
### Turning off locale detection [#locale-detection]
424+
### `localeDetection` [#locale-detection]
425425

426426
The middleware will [detect a matching locale](/docs/routing/middleware#locale-detection) based on your routing configuration & the incoming request and will either pass the request through for a matching locale or redirect to one that matches.
427427

@@ -438,14 +438,14 @@ export const routing = defineRouting({
438438

439439
In this case, only the locale prefix and a potentially [matching domain](#domains) are used to determine the locale.
440440

441-
### Locale cookie [#locale-cookie]
441+
### `localeCookie`
442442

443443
If a user changes the locale to a value that doesn't match the `accept-language` header, `next-intl` will set a session cookie called `NEXT_LOCALE` that contains the most recently detected locale. This is used to [remember the user's locale](/docs/routing/middleware#locale-detection) preference for subsequent requests.
444444

445445
By default, the cookie will be configured with the following attributes:
446446

447447
2. [**`sameSite`**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#samesitesamesite-value): This value is set to `lax` so that the cookie can be set when coming from an external site.
448-
3. [**`path`**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#pathpath-value): This value is not set by default, but will use the value of your [`basePath`](#base-path) if configured.
448+
3. [**`path`**](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie#pathpath-value): This value is not set by default, but will use the value of your [`basePath`](#basepath) if configured.
449449

450450
If you have more specific requirements, you can adjust these settings accordingly:
451451

@@ -492,7 +492,7 @@ Please note that legal requirements may vary by region, so it's advisable to ver
492492

493493
</Details>
494494

495-
### Alternate links [#alternate-links]
495+
### `alternateLinks` [#alternate-links]
496496

497497
The middleware automatically sets [the `link` header](https://developers.google.com/search/docs/specialty/international/localized-versions#http) to inform search engines that your content is available in different languages. Note that this automatically integrates with your routing strategy and will generate the correct links based on your configuration.
498498

@@ -559,7 +559,11 @@ export default async function middleware(request: NextRequest) {
559559

560560
</Details>
561561

562-
### Base path
562+
## `next.config.ts` [#next-config]
563+
564+
Apart from your routing configuration, `next-intl` will also incorporate settings from [`next.config.ts`](https://nextjs.org/docs/pages/api-reference/config/next-config-js).
565+
566+
### `basePath`
563567

564568
The `next-intl` middleware as well as [the navigation APIs](/docs/routing/navigation) will automatically pick up a [`basePath`](https://nextjs.org/docs/app/api-reference/next-config-js/basePath) that you might have configured in your `next.config.js`.
565569

@@ -578,8 +582,8 @@ export const config = {
578582
};
579583
```
580584

581-
### Trailing slash
585+
### `trailingSlash`
582586

583587
If you have [`trailingSlash`](https://nextjs.org/docs/app/api-reference/next-config-js/trailingSlash) set to `true` in your Next.js config, this setting will be taken into account by the middleware and the navigation APIs.
584588

585-
Note that if you're using [localized pathnames](#pathnames), your internal and external pathnames can be defined either with or without a trailing slash as they will be normalized internally.
589+
Note that if you're using [`pathnames`](#pathnames), your internal and external pathnames can be defined either with or without a trailing slash as they will be normalized internally.

docs/src/pages/docs/routing/middleware.mdx

+4-13
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ import Details from '@/components/Details';
88
routing](/docs/getting-started/app-router).
99
</Callout>
1010

11-
The middleware receives a [`routing`](/docs/routing#define-routing) configuration and takes care of:
11+
The middleware can be created via `createMiddleware`.
12+
13+
It receives a [`routing`](/docs/routing#define-routing) configuration and takes care of:
1214

1315
1. Locale negotiation
1416
2. Applying relevant redirects & rewrites
@@ -45,7 +47,7 @@ In this case, the locale is detected based on these priorities:
4547
3. A locale can be matched based on the [`accept-language` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Accept-Language)
4648
4. As a last resort, the `defaultLocale` is used
4749

48-
To change the locale, users can visit a prefixed route. This will take precedence over a previously matched locale that is saved in a cookie or the `accept-language` header and will update the previous cookie value.
50+
To change the locale, users can visit a prefixed route. This will take precedence over a previously matched locale that is saved in a cookie or the `accept-language` header and will update a previous cookie value.
4951

5052
**Example workflow:**
5153

@@ -92,17 +94,6 @@ Since the middleware is aware of all your domains, if a domain receives a reques
9294
3. When the link is clicked, a request to `us.example.com/fr` is initiated.
9395
4. The middleware recognizes that the user wants to switch to another domain and responds with a redirect to `ca.example.com/fr`.
9496

95-
<Details id="domain-matching">
96-
<summary>How is the best-matching domain for a given locale detected?</summary>
97-
98-
The best-matching domain is detected based on these priorities:
99-
100-
1. Stay on the current domain if the locale is supported here
101-
2. Use an alternative domain where the locale is configured as the `defaultLocale`
102-
3. Use an alternative domain that supports the locale
103-
104-
</Details>
105-
10697
## Matcher config
10798

10899
The middleware is intended to only run on pages, not on arbitrary files that you serve independently of the user locale (e.g. `/favicon.ico`).

0 commit comments

Comments
 (0)