Skip to content

Commit 88cd9ca

Browse files
docs: move stuff around in load.mdx
1 parent 337f71e commit 88cd9ca

File tree

1 file changed

+14
-10
lines changed
  • src/routes/solid-router/reference/load-functions

1 file changed

+14
-10
lines changed

src/routes/solid-router/reference/load-functions/load.mdx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ function loadUser({ params, location }) {
2323
<Route path="/users/:id" component={User} load={loadUser} />;
2424
```
2525

26-
| key | type | description |
27-
| -------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
28-
| params | object | The route parameters (same value as calling [`useParams()`](/solid-router/reference/primitives/use-params) inside the route component) |
29-
| location | `{ pathname, search, hash, query, state, key}` | An object that used to get more information about the path (corresponds to [`useLocation()`](/solid-router/reference/primitives/use-location)) |
30-
| intent | `"initial", "navigate", "native", "preload"` | Indicates why this function is being called. <ul><li>"initial" - the route is being initially shown (ie page load)</li><li>"native" - navigate originated from the browser (eg back/forward)</li><li>"navigate" - navigate originated from the router (eg call to navigate or anchor clicked)</li><li>"preload" - not navigating, just preloading (eg link hover)</li></ul> |
31-
3226
A common pattern is to export the load function and data wrappers that correspond to a route in a dedicated `route.data.js` file.
3327
This imports the data functions without loading anything else.
3428

@@ -51,7 +45,7 @@ The return value of the `load` function is passed to the page component as a `da
5145
```js
5246
//pages/users/[id].jsx
5347
export default function User(props) {
54-
return <p>{ props.data().name }</p>
48+
return <p>{props.data().name}</p>;
5549
}
5650
```
5751

@@ -78,7 +72,9 @@ const User = lazy(() => import("./pages/users/[id].js"));
7872

7973
import { cache } from "@solidjs/router";
8074

81-
export const getUser = cache((id) => { /* do loading */ }, "users");
75+
export const getUser = cache((id) => {
76+
/* do loading */
77+
}, "users");
8278
export const loadUser = ({ params, location }) => fetchUser(params.id);
8379
export default loadUser;
8480
```
@@ -89,7 +85,15 @@ export default loadUser;
8985
import { getUser } from "./[id].data.js";
9086

9187
export default function User(props) {
92-
const user = createAsync(() => getUser(props.params.id));
93-
return <p>{ user().name }</p>
88+
const user = createAsync(() => getUser(props.params.id));
89+
return <p>{user().name}</p>;
9490
}
9591
```
92+
93+
## Props
94+
95+
| key | type | description |
96+
| -------- | ---------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
97+
| params | object | The route parameters (same value as calling [`useParams()`](/solid-router/reference/primitives/use-params) inside the route component) |
98+
| location | `{ pathname, search, hash, query, state, key}` | An object that used to get more information about the path (corresponds to [`useLocation()`](/solid-router/reference/primitives/use-location)) |
99+
| intent | `"initial", "navigate", "native", "preload"` | Indicates why this function is being called. <ul><li>"initial" - the route is being initially shown (ie page load)</li><li>"native" - navigate originated from the browser (eg back/forward)</li><li>"navigate" - navigate originated from the router (eg call to navigate or anchor clicked)</li><li>"preload" - not navigating, just preloading (eg link hover)</li></ul> |

0 commit comments

Comments
 (0)