Skip to content

Commit 845dcec

Browse files
committed
quick blurb about server-rendering
1 parent 4f19059 commit 845dcec

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

docs/guides/server-rendering.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,32 @@
11
Server Rendering
22
================
33

4+
Server rendering of your app with react router is no different than
5+
anything else, really, you just pass in the requested path to
6+
`Router.run` and then use `React.renderToString` instead of
7+
`React.render`.
8+
9+
```js
10+
var App = React.createClass({
11+
render: function () {
12+
return <div>Hi</div>;
13+
}
14+
});
15+
16+
var routes = (
17+
<Route handler={App} path="/" />
18+
);
19+
20+
// if using express it might look like this
21+
app.use(function (req, res) {
22+
// pass in `req.path` and the router will immediately match
23+
Router.run(routes, req.path, function(Handler) {
24+
var content = <Handler/>;
25+
res.render('main', {content: content});
26+
});
27+
});
28+
```
29+
30+
We'll add some more here soon, but for the adventurous few, this ought
31+
to get you started.
432

0 commit comments

Comments
 (0)