Skip to content
Merged
Changes from 11 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
33 changes: 33 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,39 @@ const { post } = Astro.props;
<h1>{id}: {post.name}</h1>
```

### `routePattern`

<p>

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

A property available in [`getStaticPaths()`](#getstaticpaths) options to access the current [`routePattern`](/en/reference/api-reference/#routepattern) as a string.

This provides data from the [Astro render context](/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.

`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"
---
import { getLocalizedData } from "../../../utils/i18n";

export async function getStaticPaths({ routePattern }) {
const response = await fetch('...');
const data = await response.json();

console.log(routePattern); // [...locale]/[files]/[slug]

// Your custom helper will be responsible of parsing the `routePattern` value to return an array (for each locale) of objects matching
// `{ params: { locale: "en", files: "localized-string", slug: "localized-slug" }, props: { /* your data */ } }`
return data.flatMap((file) => getLocalizedData(file, routePattern));
}

const { locale, files, slug } = Astro.params;
---
```

### `paginate()`

<p>
Expand Down