Advertisement
xapu

Untitled

Oct 23rd, 2017
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.02 KB | None | 0 0
  1. import React from 'react'
  2. import ReactDOM from 'react-dom'
  3.  
  4. import { BrowserRouter, Link, Route } from 'react-router-dom'
  5.  
  6. const Carnitas = () => (
  7. <div>
  8. <h1>Carnitas</h1>
  9. </div>
  10. )
  11. const Tacos = ({ match }) => // here's a nested div
  12. (
  13. <div>
  14. <div>
  15. <Link to='/carnitas'>carnitas</Link>
  16. </div>
  17.  
  18. {/* here's a nested Route,
  19. match.url helps us make a relative path */}
  20. <Route path={match.url + '/carnitas'} component={Carnitas} />
  21. </div>
  22. )
  23.  
  24. const App = () => (
  25. <BrowserRouter>
  26. {/* here's a div */}
  27. <div>
  28. <nav>
  29. <div>
  30. <Link to='/tacos'>t</Link>
  31. </div>
  32. <Link to='/bacos'>b</Link>
  33. <div />
  34. </nav>
  35. {/* here's a Route */}
  36. <Route path='/tacos' component={Tacos} />
  37. <Route path='/bacos' component={Carnitas} />
  38. </div>
  39. </BrowserRouter>
  40. )
  41.  
  42. // when the url matches `/tacos` this component renders
  43.  
  44. ReactDOM.render(
  45. <BrowserRouter>
  46. <App />
  47. </BrowserRouter>,
  48. root
  49. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement