Created
July 6, 2015 23:40
-
-
Save ariofrio/c12e24d1f177170687d4 to your computer and use it in GitHub Desktop.
Using Director.js with React.js (uses ES6 extensions)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import router from './router.jsx'; | |
import A from './A.jsx'; | |
import B from './B.jsx'; | |
import C from './C.jsx'; | |
router.on('/a', () => { React.render(<A />, document.body); }); | |
router.on('/b', () => { React.render(<B />, document.body); }); | |
router.on('/c', () => { React.render(<C />, document.body); }); | |
router.init(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// <script src="//cdnjs.cloudflare.com/ajax/libs/Director/1.2.8/director.js"></script> | |
// Or use npm and "import". | |
let router = new Router().configure({ | |
html5history: true, | |
}); | |
export { router as default }; | |
// Use in place of <a> when the link should not reload the page but simply | |
// update the route. | |
export class Link extends React.Component { | |
render() { | |
return ( | |
<a onClick={this.handleClick.bind(this)} {...this.props}> | |
{this.props.children} | |
</a> | |
); | |
} | |
handleClick(e) { | |
e.preventDefault(); | |
router.setRoute(this.props.href); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment