Skip to content

Commit

Permalink
Flux - 6 - Refactor to Separate Rendering and Routing
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenGrider committed Jul 5, 2015
1 parent f268536 commit 3403ae6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 40 deletions.
42 changes: 2 additions & 40 deletions imgur-client/src/app.jsx
Original file line number Diff line number Diff line change
@@ -1,42 +1,4 @@
var React = require('react');
var ReactRouter = require('react-router');
var HashHistory = require('react-router/lib/hashhistory');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;
var Routes = require('./routes');

var Hello = React.createClass({
render: function() {
return <h1 className="red">
{this.props.children}
</h1>
}
});

var Child1 = React.createClass({
render: function() {
return <h1>
I'm child1
{this.props.children}
</h1>
}
});

var Child2 = React.createClass({
render: function() {
return <h1>I'm the other child, Child2.</h1>
}
})

var routes = (
<Router history={new HashHistory}>
<Route path="/" component={Hello}>
<Route path="1" component={Child1}>
<Route path="2" component={Child2} />
</Route>
<Route path="2" component={Child2} />
</Route>
</Router>
)

// var element = React.createElement(Hello, {});
React.render(routes, document.querySelector('.container'));
React.render(Routes, document.querySelector('.container'));
10 changes: 10 additions & 0 deletions imgur-client/src/components/main.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var React = require('react');

module.exports = React.createClass({
render: function() {
return <div>
I'm a header.
{this.props.children}
</div>
}
});
15 changes: 15 additions & 0 deletions imgur-client/src/routes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var React = require('react');
var ReactRouter = require('react-router');
var HashHistory = require('react-router/lib/hashhistory');
var Router = ReactRouter.Router;
var Route = ReactRouter.Route;

var Main = require('./components/main');

module.exports = (
<Router history={new HashHistory}>
<Route path="/" component={Main}>

</Route>
</Router>
)

0 comments on commit 3403ae6

Please sign in to comment.