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
|`initialRoute`|`Route`| The route your application is initially showing |
36
-
|`history`|`History`| The history instance for the router |
37
-
|`basePath`|`string`| Base path string that will get prepended to all route paths |
38
-
|`resourceContext`|`ResourceContext`| Custom contextual data that will be provided to all your resources' `getKey` and `getData` methods |
39
-
|`resourceData`|`ResourceData`| Pre-resolved resource data. When provided, the router will not request resources on mount |
40
-
|`onPrefetch`|`function(RouterContext)`| Called when prefetch is triggered from a Link |
41
-
42
-
## StaticRouter
43
-
44
-
If you are planning to render your application on the server, you must use the `StaticRouter` in your server side entry. The `StaticRouter` should only be used on server as it omits all browser-only resources. It does not require a `history` prop to be provided, instead, you simply need to provide the current `location` as a string. In order to achieve this, we recommend your server side application uses [`jsdom`](https://github.com/jsdom/jsdom).
|`history`|`History`| The history instance for the router, if omitted memory history will be used (optional but recommended) |
36
+
|`location`|`string`| If `history` prop is omitted, this configures the initial location for the default memory history (optional, useful for tests and storybooks) |
37
+
|`basePath`|`string`| Base path string that will get prepended to all route paths (optional) |
38
+
|`initialRoute`|`Route`| The route your application is initially showing, it's a performance optimisation to avoid route matching cost on initial render(optional) |
39
+
|`resourceContext`|`ResourceContext`| Custom contextual data that will be provided to all your resources' `getKey` and `getData` methods (optional) |
40
+
|`resourceData`|`ResourceData`| Pre-resolved resource data. When provided, the router will not request resources on mount (optional) |
41
+
|`onPrefetch`|`function(RouterContext)`| Called when prefetch is triggered from a Link (optional) |
69
42
70
43
## MemoryRouter
71
44
72
45
The `MemoryRouter` component can be used for your application's unit tests.
73
46
74
47
```js
75
48
it('should send right props after render with routes', () => {
Copy file name to clipboardExpand all lines: docs/router/ssr.md
+17-12Lines changed: 17 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -22,22 +22,25 @@ import { RouteComponent } from 'react-resource-router';
22
22
23
23
exportconstApp= () => (
24
24
<>
25
+
<Navigation />
25
26
<RouteComponent />
27
+
<Footer />
26
28
</>
27
29
);
28
30
```
29
31
30
-
The reason for this is that currently, you will need to use the [`Router`](#router-component) component on the client and the [`StaticRouter`](#staticrouter-component) component on the server. Following the above composition pattern will allow you to use the correct router in your server side entry and client side entry respectively. This could look something like the following examples:
32
+
When however you need to SSR your app, we need pass different props to Router, as `createBrowserHistory` does not really work on server, so we recommend to use `location` instead (or pass your own `MemoryHistory` if needed)
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.
60
65
61
-
Luckily the `StaticRouter` provides a convenient static method to do this for us.
66
+
Luckily the `Router` provides a convenient static method to do this for us.
Notice that we do not need to provide any `resourceData` object to the `ServerApp`, the `StaticRouter` handles this for us internally.
81
+
Notice that we do not need to provide any `resourceData` object to the `ServerApp`, the `Router` handles this for us internally.
77
82
78
-
To prevent slow APIs from causing long renders on the server you can optionally pass in `timeout` as an option to `StaticRouter.requestResources`. If a route resource does not return within the specified time then its data and promise will be set to null.
83
+
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.
0 commit comments