Guest User

Untitled

a guest
Sep 25th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. import React, { Component } from 'react'
  2. import { NavLink, Switch, Route } from 'react-router-dom'
  3. import './App.css'
  4.  
  5. const Navigation = () => (
  6. <nav>
  7. <ul>
  8. <li>
  9. <NavLink exact activeClassName="current" to="/">Home</NavLink>
  10. </li>
  11. <li>
  12. <NavLink exact activeClassName="current" to="/about">About</NavLink>
  13. </li>
  14. <li>
  15. <NavLink exact activeClassName="current" to="/contact">Contact</NavLink>
  16. </li>
  17. </ul>
  18. </nav>
  19. )
  20.  
  21. const Home = () => (
  22. <div>
  23. <h1>Home</h1>
  24. <p>Home stuff</p>
  25. </div>
  26. )
  27.  
  28. const About = () => (
  29. <div>
  30. <h1>About</h1>
  31. <p>About stuff</p>
  32. </div>
  33. )
  34.  
  35. const Contact = () => (
  36. <div>
  37. <h1>Contact</h1>
  38. <p>Contact stuff</p>
  39. </div>
  40. )
  41.  
  42. const Main = () => (
  43. <Switch>
  44. <Route exact path="/" component={Home} />
  45. <Route exact path="/about" component={About} />
  46. <Route exact path="/contact" component={Contact} />
  47. </Switch>
  48. )
  49.  
  50. const App = () => (
  51. <div>
  52. <h1>Router</h1>
  53. <Navigation />
  54. <Main />
  55. </div>
  56. )
  57.  
  58. export default App
  59.  
  60. // index.js:
  61.  
  62. import { BrowserRouter } from 'react-router-dom'
  63.  
  64. ReactDOM.render(
  65. <BrowserRouter>
  66. <App />
  67. </BrowserRouter>,
  68. document.getElementById('root')
  69. )
Add Comment
Please, Sign In to add comment