Preload
Edit this pageWith smart caches waterfalls are still possible with view logic and with lazy loaded code. With preload functions, fetching the data parallel to loading the route is possible to allow use of the data as soon as possible. The preload function can be called when the Route is loaded or eagerly when links are hovered.
As its only argument, the preload 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 preload 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 preload
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.