Resources or router loaders
They compose: load the page's record in a loader, and fetch comments or recommendations in a resource inside the page so they do not delay navigation.
Router loader |
useResource |
|
|---|---|---|
| Runs | before the route renders, during navigation | when the component is created |
| Blocks the page | yes (pending UI after pendingMs) |
no; render loading UI or use <Suspense> |
| Cache | keyed by route, params and deps; staleTime, preload, invalidate |
none; share the resource |
| Inputs | URL params and search | any signal |
| Cancellation | signal aborts on a newer navigation |
signal aborts on a newer fetch or disposal |
| Server rendering | awaited by router.ready(); data in router.dehydrate() |
awaited by renderToStringAsync; data keyed by key |
| Use for | the record the page is about | secondary data on the page, data that follows a control |
They compose: load the page's record in a loader, and fetch comments or recommendations in a resource inside the page so they do not delay navigation.