Skip to content

Commit 485e8ba

Browse files
Update usePreloadRoute reference page (#1401)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 4fafba9 commit 485e8ba

File tree

1 file changed

+57
-17
lines changed

1 file changed

+57
-17
lines changed

src/routes/solid-router/reference/primitives/use-preload-route.mdx

Lines changed: 57 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -9,36 +9,76 @@ tags:
99
- optimization
1010
- prefetch
1111
- manual
12-
version: '1.0'
12+
version: "1.0"
1313
description: >-
1414
Manually preload routes with usePreloadRoute - optimize performance by
1515
prefetching route data before navigation in your SolidJS app.
1616
---
1717

18-
`usePreloadRoute` returns a function that can be used to preload a route manually.
18+
The `usePreloadRoute` function is a utility for manually preloading a route.
19+
20+
## Import
1921

2022
```ts
21-
const preload = usePreloadRoute();
23+
import { usePreloadRoute } from "@solidjs/router";
24+
```
25+
26+
## Type
2227

23-
preload(`/users/settings`, { preloadData: true });
28+
```ts
29+
const usePreloadRoute: () => (
30+
url: string | URL,
31+
options?: { preloadData?: boolean }
32+
) => void;
2433
```
2534

26-
## Usage
35+
## Parameters
36+
37+
### `url`
38+
39+
**Type:** `string | URL`
40+
**Required:** Yes
41+
42+
The route path to preload.
43+
Accepts either a `string` path or a [URL](https://developer.mozilla.org/en-US/docs/Web/API/URL) object.
44+
45+
### `options`
46+
47+
- **Type:** `{ preloadData?: boolean }`
48+
- **Required:** No
2749

28-
Routes are preloaded by default within Solid Router contexts.
29-
This helper is useful when you want to preload a route in response to some other event, such as a button click or a timer.
50+
A configuration object with the following properties:
3051

31-
## Type Signature
52+
#### `preloadData`
3253

33-
### Parameters
54+
- **Type:** `boolean`
55+
- **Default:** `false`
3456

35-
| Parameter | Type | Required | Description |
36-
| --------- | -------- | -------- | ------------------------------------ |
37-
| `to` | `To` | Yes | The route path to preload |
38-
| `options` | `object` | No | Configuration options for preloading |
57+
When `true`, triggers the route's data loading in addition to preloading the route itself.
58+
59+
## Return value
60+
61+
None.
62+
63+
## Examples
64+
65+
### Basic usage
66+
67+
```tsx
68+
import { usePreloadRoute } from "@solidjs/router";
69+
70+
function SettingsButton() {
71+
const preload = usePreloadRoute();
72+
73+
return (
74+
<button onClick={() => preload("/users/settings", { preloadData: true })}>
75+
Load settings
76+
</button>
77+
);
78+
}
79+
```
3980

40-
### Options
81+
## Related
4182

42-
| Option | Type | Default | Description |
43-
| ------------- | --------- | ------- | ------------------------------------------------------------------- |
44-
| `preloadData` | `boolean` | `false` | Whether to preload the route's data in addition to the route itself |
83+
- [`<A>`](/solid-router/reference/components/a)
84+
- [`preload`](/solid-router/reference/preload-functions/preload)

0 commit comments

Comments
 (0)