diff --git a/src/content/docs/en/guides/internationalization.mdx b/src/content/docs/en/guides/internationalization.mdx index 81466312419b2..6a52b5d15a060 100644 --- a/src/content/docs/en/guides/internationalization.mdx +++ b/src/content/docs/en/guides/internationalization.mdx @@ -201,11 +201,11 @@ Astro provides helper functions for your middleware so you can control your own ```js title="src/middleware.js" import { defineMiddleware } from "astro:middleware"; import { redirectToDefaultLocale } from "astro:i18n"; // function available with `manual` routing -export const onRequest = defineMiddleware(async (ctx, next) => { - if (ctx.url.startsWith("/about")) { +export const onRequest = defineMiddleware((ctx, next) => { + if (ctx.url.pathname.startsWith("/about")) { return next(); } else { - return redirectToDefaultLocale(302); + return redirectToDefaultLocale(ctx, 302); } }) ``` diff --git a/src/content/docs/en/guides/middleware.mdx b/src/content/docs/en/guides/middleware.mdx index 86ab9d566ac2d..f3ecbd12d9d4b 100644 --- a/src/content/docs/en/guides/middleware.mdx +++ b/src/content/docs/en/guides/middleware.mdx @@ -257,6 +257,8 @@ When you have multiple middleware functions chained via [sequence()](#chaining-m Calling `next()` with this signature will create a new `Request` object using the old `ctx.request`. This means that trying to consume `Request.body`, either before or after this rewrite, will throw a runtime error. This error is often raised with [Astro Actions that use HTML forms](/en/guides/actions/#call-actions-from-an-html-form-action). In these cases, we recommend handling rewrites from your Astro templates using `Astro.rewrite()` instead of using middleware. ```js title="src/middleware.js" +import { sequence } from "astro:middleware"; + // Current URL is https://example.com/blog // First middleware function diff --git a/src/content/docs/en/guides/prefetch.mdx b/src/content/docs/en/guides/prefetch.mdx index 7a1b374797137..c2144251340d4 100644 --- a/src/content/docs/en/guides/prefetch.mdx +++ b/src/content/docs/en/guides/prefetch.mdx @@ -100,7 +100,7 @@ As some navigation might not always appear as `` links, you can also prefet import { prefetch } from 'astro:prefetch'; const btn = document.getElementById('btn'); - btn.addEventListener('click', () => { + btn?.addEventListener('click', () => { prefetch('/about'); }); @@ -158,11 +158,13 @@ To use `prefetch()` programmatically with large sets of links, you can set `eage A Nice Link 20 ``` diff --git a/src/content/docs/en/guides/typescript.mdx b/src/content/docs/en/guides/typescript.mdx index a53f7ecfbc98c..baa3c89830946 100644 --- a/src/content/docs/en/guides/typescript.mdx +++ b/src/content/docs/en/guides/typescript.mdx @@ -307,13 +307,14 @@ Astro includes helpers for working with the types returned by your [`getStaticPa You can get the type of [`Astro.params`](/en/reference/api-reference/#params) with `InferGetStaticParamsType` and the type of [`Astro.props`](/en/reference/api-reference/#props) with `InferGetStaticPropsType` or you can use `GetStaticPaths` to infer both at once: -```astro title="src/pages/posts/[...id].astro" {2-6,18-19} "satisfies GetStaticPaths;" +```astro title="src/pages/posts/[...id].astro" {2-6,19-20} "satisfies GetStaticPaths;" --- import type { InferGetStaticParamsType, InferGetStaticPropsType, GetStaticPaths, } from "astro"; +import { getCollection } from "astro:content"; export const getStaticPaths = (async () => { const posts = await getCollection("blog"); @@ -328,7 +329,7 @@ export const getStaticPaths = (async () => { type Params = InferGetStaticParamsType; type Props = InferGetStaticPropsType; -const { id } = Astro.params as Params; +const { id } = Astro.params; // ^? { id: string; } const { title } = Astro.props;