JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://fb.me/react-with-addons-0.9.0.js"></script>
<script src="http://fb.me/JSXTransformer-0.9.0.js"></script>
<script src="https://rawgithub.com/flatiron/director/master/build/director.min.js"></script>
<script src="http://fb.me/react-js-fiddle-integration.js"></script>
JavaScript 1.7
/** @jsx React.DOM */
var App = React.createClass({
getInitialState: function() {
return {currentPage: 'home'};
},
componentDidMount: function() {
var router = Router({
'/home': this.setState.bind(this, {currentPage: 'home'}),
'/bio': this.setState.bind(this, {currentPage: 'bio'})
});
router.init();
},
render: function() {
var partial;
if (this.state.currentPage === 'home') {
partial = <Home />;
} else if (this.state.currentPage === 'bio') {
partial = <Bio />;
} else {
// dunno, your default page
// if you don't assign anything to partial here, you'll render nothing (undefined). In another situation you'd use the same concept to toggle between show/hide, aka render something/undefined (or null)
}
return (
<div>
<div>I am a menu that stays here</div>
<a href="#/home">Home</a> <a href="#/bio">Bio</a>
{partial}
</div>
);
}
});
var Home = React.createClass({
render: function() {
return <div>home</div>;
}
});
var Bio = React.createClass({
render: function() {
return <div>bio</div>;
}
});
React.renderComponent(<App />, document.body);