Give integrations access to routes earlier #998
Replies: 7 comments 8 replies
-
@Fryuni feel free to give your thoughts on this! FYI withastro/astro#11824 should allow exposing route data on |
Beta Was this translation helpful? Give feedback.
-
Whichever hook this information is made available would need to be re-run during the execution of the dev server or would need to receive a function for a callback like so: {
'astro:config:done': ({ routes, onRouteChanged }) => {
// Do something with the routes
onRouteChanged(newRoutes => {
// Do something with the changed routes due to an edit while running the dev server
});
},
} Instead of that, I think this would be better as a separate hook: `astro:routes:resolved`: ({ routes }) => {
// This hook is called whenever the routes list is resolved.
// If it changes, it will be called again
} It follows the same idea as the recently added As for the information in this hook, I'd like it to have at least:
A nice thing to have would be an |
Beta Was this translation helpful? Give feedback.
-
If there's a new hook, it will run after |
Beta Was this translation helpful? Give feedback.
-
I don't mind this in theory. Have you looked at what code changes would need to be made for this? In particular, for dev mode I guess we'd need access to run the hook on route changes. Do we have a place for that? |
Beta Was this translation helpful? Give feedback.
-
@florian-lefebvre if we add this route can we also deprecate providing the routes to |
Beta Was this translation helpful? Give feedback.
-
PR at withastro/astro#12329 |
Beta Was this translation helpful? Give feedback.
-
This should be merged soon, I'm closing as accepted |
Beta Was this translation helpful? Give feedback.
-
Body
Summary
Give integrations access to routes earlier
Background & Motivation
Currently, routes are only exposed in
astro:build:done
. However, if you want as an integration author to do some stuff relying on routes earlier in the lifecycle like in dev, or for typegen, you basically can't.The proposal is to expose the data earlier.
Something to keep in mind is that user routes (not injected) can change during dev so some kind of watcher may need to be exposed.
Goals
Example
When loading an astro project, no route is added after
astro:config:setup
so the initial route data could be exposed onastro:config:done
. As for the watcher, it could be onastro:server:setup
alongside the vite dev server.Beta Was this translation helpful? Give feedback.
All reactions