Advertisement
Guest User

Untitled

a guest
Apr 21st, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import history from './history'
  3.  
  4. import {
  5. BrowserRouter as Router,
  6. Route,
  7. Switch,
  8. Link
  9. } from 'react-router-dom';
  10.  
  11. class App extends Component {
  12. render() {
  13. return (
  14. <Router history={history}>
  15. <div>
  16. <Link to="/">
  17. <button>Go to home</button>
  18. </Link>
  19. <Switch>
  20. <Route exact path="/other" component={() => <Other/>} />
  21. <Route path="/" component={() => <Home/>} />
  22. </Switch>
  23. </div>
  24. </Router>
  25. );
  26. }
  27. }
  28.  
  29. class Home extends Component {
  30. render() {
  31. return (
  32. <div>
  33. THIS IS HOME WOO!
  34. <div>
  35. <Route exact path="/" component={() => <HomeController/>} />
  36. <Route exact path="/about" component={() => <About/>} />
  37. <Route exact path="/click-page" component={() => <ClickPage/>} />
  38. </div>
  39. </div>
  40. );
  41. }
  42. }
  43.  
  44. class HomeController extends Component {
  45. render() {
  46. return (
  47. <div>
  48. <Link to="/about">
  49. <button>Go to about</button>
  50. </Link>
  51. <Link to="/click-page">
  52. <button>Go to click page</button>
  53. </Link>
  54. </div>
  55. );
  56. }
  57. }
  58.  
  59. class About extends Component {
  60. render() {
  61. return (
  62. <div>
  63. ABOUT
  64. </div>
  65. );
  66. }
  67. }
  68.  
  69. function clickHandler(){
  70. console.log("doing stuff");
  71. history.push('/about');
  72. }
  73.  
  74. class ClickPage extends Component {
  75. render() {
  76. return (
  77. <button onClick={clickHandler}>
  78. DO SOMETHING THEN GO TO ABOUT
  79. </button>
  80. );
  81. }
  82. }
  83.  
  84. class Other extends Component {
  85. render() {
  86. return (
  87. <div>
  88. OTHER
  89. </div>
  90. );
  91. }
  92. }
  93.  
  94. export default App;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement