Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions docs/guides/ServerRendering.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Server rendering is a bit different than in a client because you'll want to:
- Send `30x` responses for redirects
- Fetch data before rendering (and use the router to help you do it)

To facilitate these needs, you drop one level lower than the [`<Router>`](/docs/API.md#Router) API with:
To facilitate these needs, you drop one level lower than the [`<Router>`](/docs/API.md#Router) API with:

- [`match`](/docs/API.md#match-routes-location-history-options--cb) to match the routes to a location without rendering
- `RouterContext` for synchronous rendering of route components
Expand Down Expand Up @@ -53,9 +53,25 @@ render(<Router history={history} routes={routes} />, mountNode)
You need to do

```js
match({ history, routes }, (error, redirectLocation, renderProps) => {
render(<Router {...renderProps} />, mountNode)
})
function initiateRender(history) {
match({ history, routes }, (error, redirectLocation, renderProps) => {
if (redirectLocation == null) {
render(<Router {...renderProps} />, mountNode)
} else {
switch (redirectLocation.action) {
case "PUSH":
history.push(redirectLocation);
break;
case "REPLACE":
history.replace(redirectLocation);
break;
}
initiateRender(history);
}
})
}

initiateRender(history)
```

## History Singletons
Expand Down