Skip to content

Commit b2470c3

Browse files
Set up client-side routing with react-router
- Replace the component with routes in `client.js` - Then in `routes/routes.jsx`, add `createElement()` that merges router props with `window.PROPS` if in browser Todo: - Separate or namespace `window.PROPS` so that it doesn't override any router props
1 parent 98318d9 commit b2470c3

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

client.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
var React = require('react');
21
var ReactDOM = require('react-dom');
3-
var Component = require('./Component.jsx');
4-
5-
var props = window.PROPS;
2+
var routes = require('./routes/routes.jsx');
63

74
ReactDOM.render(
8-
React.createElement(Component, props), document
5+
routes, document
96
);

routes/routes.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,14 @@ var Router = ReactRouter.Router;
44
var Route = ReactRouter.Route;
55
var browserHistory = ReactRouter.browserHistory;
66

7+
if (typeof window === 'object') {
8+
function createElement(Component, props) {
9+
return <Component {...props} {...window.PROPS} />;
10+
}
11+
}
12+
713
module.exports = (
8-
<Router history={browserHistory}>
14+
<Router history={browserHistory} createElement={createElement}>
915
<Route path='/' component={require('../Component.jsx')}>
1016
</Route>
1117
</Router>

0 commit comments

Comments
 (0)