/ Published in: Other
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import React from 'react'; import { Router, Route, Link, hashHistory } from 'react-router'; class Home extends React.Component { componentWillMount(){ this.context.router.setRouteLeaveHook( this.props.route, this.routerWillLeave ) } routerWillLeave( nextLocation ){ return `leaving home for ${nextLocation.pathname}` } render(){ } } Home.contextTypes = { router: React.PropTypes.object.isRequired } const Links = () => { return ( <nav> </nav> ) }; const App = () => { return ( <Router history={ hashHistory }> <Route path="/" component={Home}></Route> <Route path="/about" component={About}></Route> </Router> ) }; export default App;