Skip to content

Commit a748c65

Browse files
fix: add missing fallbackType option in i18n middleware() (#14084)
Co-authored-by: Yan <61414485+yanthomasdev@users.noreply.github.com>
1 parent 11368a7 commit a748c65

2 files changed

Lines changed: 18 additions & 14 deletions

File tree

src/content/docs/en/guides/internationalization.mdx

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -212,35 +212,35 @@ export const onRequest = defineMiddleware(async (ctx, next) => {
212212

213213
#### middleware function
214214

215-
The [`middleware`](#middleware-function) function manually creates Astro's i18n middleware. This allows you to extend Astro's i18n routing instead of completely replacing it.
215+
The [`middleware()`](/en/reference/modules/astro-i18n/#middleware) function manually creates Astro's i18n middleware. This allows you to extend Astro's i18n routing instead of completely replacing it.
216216

217-
You can run `middleware` with [routing options](#routing) in combination with your own middleware, using the [`sequence`](/en/reference/modules/astro-middleware/#sequence) utility to determine the order:
217+
You can run `middleware()` with [routing options](#routing) in combination with your own middleware, using the [`sequence()`](/en/reference/modules/astro-middleware/#sequence) utility to determine the order:
218218

219219
```js title="src/middleware.js"
220-
import {defineMiddleware, sequence} from "astro:middleware";
220+
import { defineMiddleware, sequence } from "astro:middleware";
221221
import { middleware } from "astro:i18n"; // Astro's own i18n routing config
222222

223223
export const userMiddleware = defineMiddleware(async (ctx, next) => {
224224
// this response might come from Astro's i18n middleware, and it might return a 404
225225
const response = await next();
226226
// the /about page is an exception and we want to render it
227-
if (ctx.url.startsWith("/about")) {
227+
if (ctx.url.pathname.startsWith("/about")) {
228228
return new Response("About page", {
229-
status: 200
229+
status: 200,
230230
});
231231
} else {
232232
return response;
233233
}
234234
});
235235

236-
237236
export const onRequest = sequence(
238237
userMiddleware,
239238
middleware({
240239
redirectToDefaultLocale: false,
241-
prefixDefaultLocale: true
242-
})
243-
)
240+
prefixDefaultLocale: true,
241+
fallbackType: "redirect",
242+
}),
243+
);
244244
```
245245

246246
## `domains`

src/content/docs/en/reference/modules/astro-i18n.mdx

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ export const onRequest = defineMiddleware((context, next) => {
285285

286286
<p>
287287

288-
**Type:** `(options: { prefixDefaultLocale: boolean, redirectToDefaultLocale: boolean }) => MiddlewareHandler`<br />
288+
**Type:** `(options: { fallbackType: "redirect" | "rewrite", prefixDefaultLocale: boolean, redirectToDefaultLocale: boolean }) => MiddlewareHandler`<br />
289289
<Since v="4.6.0" />
290290
</p>
291291

@@ -310,10 +310,14 @@ const customLogic = defineMiddleware(async (context, next) => {
310310
return response;
311311
});
312312

313-
export const onRequest = sequence(customLogic, middleware({
314-
prefixDefaultLocale: true,
315-
redirectToDefaultLocale: false
316-
}))
313+
export const onRequest = sequence(
314+
customLogic,
315+
middleware({
316+
prefixDefaultLocale: true,
317+
redirectToDefaultLocale: false,
318+
fallbackType: "redirect",
319+
}),
320+
);
317321
```
318322

319323
### `requestHasLocale()`

0 commit comments

Comments
 (0)