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
Copy file name to clipboardExpand all lines: docs/api/components.md
+52-5
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. As soon as it is mounted, it will match the current route and then call all of the matched resources' `getData` methods. Components that are subscribed to these resources either via the [`useResource`](./hooks.md#useresource) hook or [`ResourceSubscriber`](./components.md#resourcesubscriber) will progressively update according to the requests' lifecycles.
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`.
|`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 |
36
40
|`basePath`|`string`| Base path string that will get prepended to all route paths (optional) |
37
41
|`initialRoute`|`Route`| The route your application is initially showing, it's a performance optimisation to avoid route matching cost on initial render(optional) |
38
-
|`resourceContext`|`ResourceContext`| Custom contextual data that will be provided to all your resources' `getKey` and `getData` methods (optional) |
39
-
|`resourceData`|`ResourceData`| Pre-resolved resource data. When provided, the router will not request resources on mount (optional) |
40
42
|`onPrefetch`|`function(RouterContext)`| Called when prefetch is triggered from a Link (optional) |
41
43
44
+
## Resources plugin
45
+
46
+
Resources plugin enables `resources` prop on the `Route` definition
47
+
48
+
As soon as `Router` is mounted, it will match the current route and then call all of the matched resources' `getData` methods. Components that are subscribed to these resources either via the [`useResource`](./hooks.md#useresource) hook or [`ResourceSubscriber`](./components.md#resourcesubscriber) will progressively update according to the requests' lifecycles.
|`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) |
85
+
86
+
42
87
## MemoryRouter
43
88
44
89
The `MemoryRouter` component can be used for your application's unit tests.
Until React Suspense works on the server, we cannot do progressive rendering server side. To get around this, we need to `await` all resource requests to render our app _with all our resource data_ on the server.
68
68
69
-
Luckily the `Router` provides a convenient static method to do this for us.
69
+
Luckily we have a convenient static method`invokePluginLoad` to do this for us.
Notice that we do not need to provide any `resourceData` object to the `ServerApp`, the `Router` handles this for us internally.
85
94
86
-
To prevent slow APIs from causing long renders on the server you can optionally pass in `timeout` as an option to `Router.requestResources`. If a route resource does not return within the specified time then its data and promise will be set to null.
95
+
To prevent slow APIs from causing long renders on the server you can optionally pass in `timeout` as an option to `createResourcesPlugin({ timeout: ... })`. If a route resource does not return within the specified time then its data and promise will be set to null.
0 commit comments