mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
05139ef8b4
* feat: add `Astro.route` * change logic and add test * rebase * rebase * rename to `Astro.routePattern` * chore: added more tests * update test * add leading slash
25 lines
581 B
Markdown
25 lines
581 B
Markdown
---
|
|
'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]`:
|
|
|
|
```asto
|
|
---
|
|
// 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" })
|
|
}
|
|
```
|
|
|
|
|