2024-08-27 09:45:16 -05:00
|
|
|
---
|
|
|
|
'astro': minor
|
|
|
|
---
|
|
|
|
|
|
|
|
Adds a new property to the globals `Astro` and `APIContext` called `routePattern`. The `routePattern` represents the current route (component)
|
|
|
|
that is being rendered by Astro. It's usually a path pattern will look like this: `blog/[slug]`:
|
|
|
|
|
2024-09-05 09:58:23 -05:00
|
|
|
```astro
|
2024-08-27 09:45:16 -05:00
|
|
|
---
|
|
|
|
// src/pages/blog/[slug].astro
|
|
|
|
const route = Astro.routePattern;
|
|
|
|
console.log(route); // it will log "blog/[slug]"
|
|
|
|
---
|
|
|
|
```
|
|
|
|
|
|
|
|
```js
|
|
|
|
// src/pages/index.js
|
|
|
|
|
|
|
|
export const GET = (ctx) => {
|
|
|
|
console.log(ctx.routePattern) // it will log src/pages/index.js
|
|
|
|
return new Response.json({ loreum: "ipsum" })
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
|