You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Added state to .push
* Added state to replace and kept state in location
* Added state to Link, replaceTo and pushedTo
* Updated docs
---------
Co-authored-by: Liam Ma <[email protected]>
Copy file name to clipboardExpand all lines: docs/api/components.md
+23-19Lines changed: 23 additions & 19 deletions
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
## Router
2
2
3
-
The `Router` component should ideally wrap your client app as high up in the tree as possible.
3
+
The `Router` component should ideally wrap your client app as high up in the tree as possible.
4
4
5
5
If you are planning to render your application on the server, we recommend creating a composition boundary between your router and the core of your application, including your `RouteComponent`.
6
6
@@ -25,21 +25,25 @@ import { appRoutes } from './routing';
|`history`|`History`| The history instance for the router, if omitted memory history will be used (optional but recommended)|
39
-
|`plugins`|`Plugin[]`| Plugin allows you to hook into Router API and extra login on route load/prefetch/etc |
40
-
|`basePath`|`string`| Base path string that will get prepended to all route paths (optional)|
41
-
|`initialRoute`|`Route`| The route your application is initially showing, it's a performance optimisation to avoid route matching cost on initial render(optional)|
42
-
|`onPrefetch`|`function(RouterContext)`| Called when prefetch is triggered from a Link (optional)|
|`history`|`History`| The history instance for the router, if omitted memory history will be used (optional but recommended) |
43
+
|`plugins`|`Plugin[]`| Plugin allows you to hook into Router API and extra login on route load/prefetch/etc|
44
+
|`basePath`|`string`| Base path string that will get prepended to all route paths (optional) |
45
+
|`initialRoute`|`Route`| The route your application is initially showing, it's a performance optimisation to avoid route matching cost on initial render(optional) |
46
+
|`onPrefetch`|`function(RouterContext)`| Called when prefetch is triggered from a Link (optional) |
|`context`|`ResourceContext`| Custom contextual data that will be provided to all your resources' `getKey` and `getData` methods (optional) |
83
-
|`resourceData`|`ResourceData`| Pre-resolved resource data. When provided, the router will not request resources on mount (optional) |
84
-
|`timeout`|`number`|`timout` is used to prevent slow APIs from causing long renders on the server, If a route resource does not return within the specified time then its data and promise will be set to null.(optional) |
|`context`|`ResourceContext`| Custom contextual data that will be provided to all your resources' `getKey` and `getData` methods (optional) |
87
+
|`resourceData`|`ResourceData`| Pre-resolved resource data. When provided, the router will not request resources on mount (optional) |
88
+
|`timeout`|`number`|`timout` is used to prevent slow APIs from causing long renders on the server, If a route resource does not return within the specified time then its data and promise will be set to null.(optional) |
@@ -48,9 +49,10 @@ As well as returning actions that act on the resource (i.e. update and refresh),
48
49
49
50
Where `-prev-` indicates the field will remain unchanged from any previous state, possibly the inital state.
50
51
51
-
It is important to note
52
-
* The timeout state is essentially a hung loading state, with the difference that `promise = null` and `error != null`. Developers should give priority to `loading` when deciding between loading or error states for their components. Promises/errors should only ever be thrown on the client.
53
-
* The `promise` reflects the last operation, either async or explicit update. Update will clear `error`, set `data`. It will also set a `promise` consistent with that `data` so long as no async is `loading`. When `loading` the `promise` will always reflect the future `data` or `error` from the pending async.
52
+
It is important to note
53
+
54
+
- The timeout state is essentially a hung loading state, with the difference that `promise = null` and `error != null`. Developers should give priority to `loading` when deciding between loading or error states for their components. Promises/errors should only ever be thrown on the client.
55
+
- The `promise` reflects the last operation, either async or explicit update. Update will clear `error`, set `data`. It will also set a `promise` consistent with that `data` so long as no async is `loading`. When `loading` the `promise` will always reflect the future `data` or `error` from the pending async.
54
56
55
57
Additionaly `useResource` accepts additional arguments to customise behaviour, like `routerContext`.
56
58
Check out [this section](../resources/usage.md) for more details on how to use the `useResource` hook.
If you are worried about `useRouter` re-rendering too much, you can create custom router hooks using selectors that will trigger a re-render only when the selector output changes.
0 commit comments