Load
Edit this pageWith smart caches waterfalls are still possible with view logic and with lazy loaded code. With load functions, fetching the data parallel to loading the route is possible to allow use of the data as soon as possible. The load function can be called when the Route is loaded or eagerly when links are hovered.
As its only argument, the load function is passed an object that can used to access route information:
key | type | description |
---|---|---|
params | object | The route parameters (same value as calling useParams() inside the route component) |
location | { pathname, search, hash, query, state, key} | An object that used to get more information about the path (corresponds to useLocation() ) |
intent | "initial", "navigate", "native", "preload" | Indicates why this function is being called.
|
A common pattern is to export the load function and data wrappers that correspond to a route in a dedicated route.data.js
file.
This imports the data functions without loading anything else.
The return value of the load
function is passed to the page component when called at anytime other than preload
.
This initializes things in there, or alternatively the following new Data APIs can be used: