| title | Preloading |
|---|
When using the <A> component from Solid Router, routes are preloaded by default on link hover/focus to improve perceived performance.
To enhance preloading, you can define the preload function on your route definition.
When on a SolidStart application, this function can also run on the server during the initial page load to fetch data before rendering. When in a Single-Page Application (SPA), it will load the route's component and its preload function when the user hovers or focuses on a link.
| user action | route behavior |
|---|---|
| hover | with a 300ms delay to avoid excessive preloading |
| focus | immediately |
You can also use the usePreloadRoute helper to preload routes programmatically in response to events other than link hover/focus, such as button clicks or timers.
This helper will load only the route's component by default, but it can receive a configuration object to also load the data.
When a route has nested lazy components, such components will not be part of the route hierarchy, so they will not be preloaded with the route. To preload such components, you can use the usePreloadRoute helper in the parent component to load them when needed.