Skip to content
Merged
Changes from 7 commits
Commits
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
34 changes: 34 additions & 0 deletions src/content/docs/en/reference/routing-reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,40 @@
<h1>{id}: {post.name}</h1>
```

### `routePattern`

<p>

**Type:** `string` <br />
<Since v="5.15.0" />
</p>

A string parameter [`getStaticPaths()`](#getstaticpaths) to access the current [`routePattern`](/en/reference/api-reference/#routepattern).

This provides data from the [Astro render context](https://docs.astro.build/en/reference/api-reference/) that would not otherwise be available within the scope of `getStaticPaths()` and can be useful to calculate the `params` and `props` for each page route.

Check failure on line 183 in src/content/docs/en/reference/routing-reference.mdx

View workflow job for this annotation

GitHub Actions / Check Links

Unwanted absolute link in src/content/docs/en/reference/routing-reference.mdx, line 183: https://docs.astro.build/en/reference/api-reference/ Suggested fix: /en/reference/api-reference/

`routePattern` always reflects the original dynamic segment definition in the file path (e.g. `/[...locale]/[slug]`), unlike `params`, which are explicit values for a page (e.g. `/fr/post-1/`).

```astro title="src/pages/[...locale]/[files]/[slug].astro"
---
export async function getStaticPaths({ routePattern }) {
// Calculate the appropriate params based on the routePattern
const params = [];
// e.g. read route pattern and translate the [files] segment to all locales
if (routePattern.includes("[files]")) {
locales.forEach((locale) => {
params.push({ files: getMessage(locale, "files") });
});
}
return { params };
}
const { page } = Astro.props;
---
```

### `paginate()`

<p>
Expand Down
Loading