@@ -138,10 +138,13 @@ var App = React.createClass({
138
138
}
139
139
});
140
140
141
+ // Declare the history outside of the `render` function.
142
+ var history = new HashHistory ();
143
+
141
144
// Finally we render a `Router` component with some `Route`s, it'll do all
142
145
// the fancy routing stuff for us.
143
146
React .render ((
144
- < Router history= {new HashHistory }>
147
+ < Router history= {history }>
145
148
< Route path= " /" component= {App}>
146
149
< Route path= " about" component= {About}/ >
147
150
< Route path= " inbox" component= {Inbox}/ >
@@ -153,6 +156,7 @@ React.render((
153
156
If you're not digging the JSX route config you can use plain objects:
154
157
155
158
``` js
159
+ var history = new HashHistory ();
156
160
var routes = {
157
161
path: ' /' ,
158
162
component: App,
@@ -162,7 +166,7 @@ var routes = {
162
166
]
163
167
};
164
168
165
- React .render (< Router history= {new HashHistory } children= {routes}/ > , document .body );
169
+ React .render (< Router history= {history } children= {routes}/ > , document .body );
166
170
```
167
171
168
172
Adding more UI
@@ -190,8 +194,9 @@ var Inbox = React.createClass({
190
194
}
191
195
});
192
196
197
+ var history = new HashHistory ();
193
198
React .render ((
194
- < Router history= {new HashHistory }>
199
+ < Router history= {history }>
195
200
< Route component= {App}>
196
201
< Route path= " about" component= {About}/ >
197
202
< Route path= " inbox" component= {Inbox}>
0 commit comments