File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 1
1
Server Rendering
2
2
================
3
3
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.
4
32
You can’t perform that action at this time.
0 commit comments