Skip to content

Instantly share code, notes, and snippets.

@JustinCarmony
Created October 30, 2014 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JustinCarmony/b88af52a2d4ff0b86be2 to your computer and use it in GitHub Desktop.
Save JustinCarmony/b88af52a2d4ff0b86be2 to your computer and use it in GitHub Desktop.
/** @jsx React.DOM */
var React = require('./vendor/js/react');
var page = require('./vendor/js/page');
var jQuery = require('./vendor/js/jquery');
var Page1 = React.createClass({
render: <div>Hi!</div>
});
var Page2 = React.createClass({
render: function () {
return <div>what?</div>
}
});
var PageNotFound = React.createClass({
render: function() {
return <div>Page Not Found</div>
}
});
var Router = React.createClass({
render: function () {
return this.state.component;
},
getInitialState: function () {
return { component: <div /> };
},
componentDidMount: function () {
var self = this;
page('/', function (ctx) {
self.setState({ component: <Page1 /> });
});
page('/users/:id', function (ctx) {
self.setState({ component: <Page2 params={ctx.params} /> });
});
page('*', function (ctx) {
self.setState({ component: <PageNotFound /> });
});
page.start();
}
});
jQuery(document).ready(function(){
React.render(<Router />, document.getElementById('body'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment