|
9 | 9 | - optimization |
10 | 10 | - prefetch |
11 | 11 | - manual |
12 | | -version: '1.0' |
| 12 | +version: "1.0" |
13 | 13 | description: >- |
14 | 14 | Manually preload routes with usePreloadRoute - optimize performance by |
15 | 15 | prefetching route data before navigation in your SolidJS app. |
16 | 16 | --- |
17 | 17 |
|
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 |
19 | 21 |
|
20 | 22 | ```ts |
21 | | -const preload = usePreloadRoute(); |
| 23 | +import { usePreloadRoute } from "@solidjs/router"; |
| 24 | +``` |
| 25 | + |
| 26 | +## Type |
22 | 27 |
|
23 | | -preload(`/users/settings`, { preloadData: true }); |
| 28 | +```ts |
| 29 | +const usePreloadRoute: () => ( |
| 30 | + url: string | URL, |
| 31 | + options?: { preloadData?: boolean } |
| 32 | +) => void; |
24 | 33 | ``` |
25 | 34 |
|
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 |
27 | 49 |
|
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: |
30 | 51 |
|
31 | | -## Type Signature |
| 52 | +#### `preloadData` |
32 | 53 |
|
33 | | -### Parameters |
| 54 | +- **Type:** `boolean` |
| 55 | +- **Default:** `false` |
34 | 56 |
|
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 | +``` |
39 | 80 |
|
40 | | -### Options |
| 81 | +## Related |
41 | 82 |
|
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