Skip to content

Commit 7f08d63

Browse files
docs: Add section about revalidation of localized pathnames to middleware docs (#870 by @LouisCuvelier)
Fixes #846 --------- Co-authored-by: Jan Amann <jan@amann.work>
1 parent 5282232 commit 7f08d63

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

docs/pages/docs/routing/middleware.mdx

+47
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,53 @@ export default createMiddleware({
343343
APIs](/docs/routing/navigation#localized-pathnames) in your components.
344344
</Callout>
345345

346+
<details>
347+
<summary>How can I revalidate localized pathnames?</summary>
348+
349+
Depending on if a route is generated statically (at build time) or dynamically (at runtime), [`revalidatePath`](https://nextjs.org/docs/app/api-reference/functions/revalidatePath) needs to be called either for the localized or the internal pathname.
350+
351+
Let's take an example with this folder structure:
352+
```
353+
app
354+
└── [locale]
355+
└── news
356+
└── [slug]
357+
```
358+
359+
… and this middleware configuration:
360+
361+
```tsx filename="middleware.ts"
362+
import createMiddleware from 'next-intl/middleware';
363+
364+
export default createMiddleware({
365+
defaultLocale: 'en',
366+
locales: ['en', 'fr'],
367+
pathnames: {
368+
'/news/[slug]': {
369+
en: '/news/[slug]',
370+
fr: '/infos/[slug]'
371+
}
372+
}
373+
});
374+
```
375+
376+
Depending on whether `some-article` was included in [`generateStaticParams`](https://nextjs.org/docs/app/api-reference/functions/generate-static-params) or not, you can revalidate the route like this:
377+
378+
```tsx
379+
// Statically generated at build time
380+
revalidatePath('/fr/news/some-article')
381+
382+
// Dynamically generated at runtime:
383+
revalidatePath('/fr/infos/some-article')
384+
```
385+
386+
When in doubt, you can revalidate both paths to be on the safe side.
387+
388+
See also [`vercel/next.js#59825`](https://github.com/vercel/next.js/issues/59825).
389+
390+
</details>
391+
392+
346393
### Matcher config
347394

348395
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)