mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
8309c61f0d
Co-authored-by: Luiz Ferraz <luiz@lferraz.com> Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
50 lines
No EOL
1.4 KiB
Markdown
50 lines
No EOL
1.4 KiB
Markdown
---
|
|
'astro': minor
|
|
---
|
|
|
|
Adds a new `astro:routes:resolved` hook to the Integration API. Also update the `astro:build:done` hook by deprecating `routes` and adding a new `assets` map.
|
|
|
|
When building an integration, you can now get access to routes inside the `astro:routes:resolved` hook:
|
|
|
|
```js
|
|
const integration = () => {
|
|
return {
|
|
name: 'my-integration',
|
|
hooks: {
|
|
'astro:routes:resolved': ({ routes }) => {
|
|
console.log(routes)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
This hook runs before `astro:config:done`, and whenever a route changes in development.
|
|
|
|
The `routes` array from `astro:build:done` is now deprecated, and exposed properties are now available on `astro:routes:resolved`, except for `distURL`. For this, you can use the newly exposed `assets` map:
|
|
|
|
```diff
|
|
const integration = () => {
|
|
+ let routes
|
|
return {
|
|
name: 'my-integration',
|
|
hooks: {
|
|
+ 'astro:routes:resolved': (params) => {
|
|
+ routes = params.routes
|
|
+ },
|
|
'astro:build:done': ({
|
|
- routes
|
|
+ assets
|
|
}) => {
|
|
+ for (const route of routes) {
|
|
+ const distURL = assets.get(route.pattern)
|
|
+ if (distURL) {
|
|
+ Object.assign(route, { distURL })
|
|
+ }
|
|
+ }
|
|
console.log(routes)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
``` |