Posted By

dylansong on 06/08/16


Tagged


Versions (?)

4.nested-routes/


 / Published in: Other
 

  1. import React from 'react';
  2. import { Router, Route, Link, hashHistory } from 'react-router';
  3.  
  4. const Home = ( props ) => <div><h1>Home</h1><Links />{props.children}</div>;
  5. const About = ( props ) => <div><h1>About</h1>{props.children}</div>;
  6. const Contact = () => <div><h1>Contact</h1></div>;
  7. const Links = () =>
  8. <nav>
  9. <Link to="/">Home</Link>
  10. <Link to="/about">About</Link>
  11. {/* <Link to="/contact">Contact</Link> */}
  12. <Link to="/about/contact">Contact</Link>
  13. </nav>
  14.  
  15. const App = () => {
  16. return (
  17. <Router history={ hashHistory }>
  18. <Route path="/" component={ Home }>
  19. <Route path="about" component={ About }>
  20. {/* <Route path="/contact" component={ Contact }></Route> */}
  21. <Route path="contact" component={ Contact }></Route>
  22. </Route>
  23. </Route>
  24. </Router>
  25. )
  26. };
  27.  
  28. export default App;
  29.  

Report this snippet  

You need to login to post a comment.