File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load Diff This file was deleted.
Original file line number Diff line number Diff line change 33 "version" : " 0.1.0" ,
44 "private" : true ,
55 "dependencies" : {
6- "@testing-library/jest-dom" : " ^4.2 .4" ,
7- "@testing-library/react" : " ^9.3.2 " ,
8- "@testing-library/user-event" : " ^7 .1.2 " ,
9- "axios" : " ^0.19 .2" ,
10- "bootstrap" : " ^4.4.1 " ,
11- "react" : " ^16.13 .0" ,
12- "react-dom" : " ^16.13 .0" ,
13- "react-router-dom" : " ^5.1.2 " ,
14- "react-scripts" : " 3.4.0 "
6+ "@testing-library/jest-dom" : " ^5.16 .4" ,
7+ "@testing-library/react" : " ^13.0.1 " ,
8+ "@testing-library/user-event" : " ^14 .1.1 " ,
9+ "axios" : " ^0.27 .2" ,
10+ "bootstrap" : " ^4.6.2 " ,
11+ "react" : " ^18.2 .0" ,
12+ "react-dom" : " ^18.2 .0" ,
13+ "react-router-dom" : " ^6.4.0 " ,
14+ "react-scripts" : " 5.0.1 "
1515 },
1616 "scripts" : {
1717 "start" : " react-scripts start" ,
Original file line number Diff line number Diff line change 11import React , { Component } from "react" ;
2- import { Switch , Route , Link } from "react-router-dom" ;
2+ import { Routes , Route , Link } from "react-router-dom" ;
33import "bootstrap/dist/css/bootstrap.min.css" ;
44import "./App.css" ;
55
@@ -30,11 +30,12 @@ class App extends Component {
3030 </ nav >
3131
3232 < div className = "container mt-3" >
33- < Switch >
34- < Route exact path = { [ "/" , "/tutorials" ] } component = { TutorialsList } />
35- < Route exact path = "/add" component = { AddTutorial } />
36- < Route path = "/tutorials/:id" component = { Tutorial } />
37- </ Switch >
33+ < Routes >
34+ < Route path = "/" element = { < TutorialsList /> } />
35+ < Route path = "/tutorials" element = { < TutorialsList /> } />
36+ < Route path = "/add" element = { < AddTutorial /> } />
37+ < Route path = "/tutorials/:id" element = { < Tutorial /> } />
38+ </ Routes >
3839 </ div >
3940 </ div >
4041 ) ;
Original file line number Diff line number Diff line change 1+ import { useLocation , useNavigate , useParams } from "react-router-dom" ;
2+
3+ export const withRouter = ( Component ) => {
4+ function ComponentWithRouterProp ( props ) {
5+ let location = useLocation ( ) ;
6+ let navigate = useNavigate ( ) ;
7+ let params = useParams ( ) ;
8+ return < Component { ...props } router = { { location, navigate, params } } /> ;
9+ }
10+ return ComponentWithRouterProp ;
11+ } ;
Original file line number Diff line number Diff line change 11import React , { Component } from "react" ;
22import TutorialDataService from "../services/tutorial.service" ;
3+ import { withRouter } from '../common/with-router' ;
34
4- export default class Tutorial extends Component {
5+ class Tutorial extends Component {
56 constructor ( props ) {
67 super ( props ) ;
78 this . onChangeTitle = this . onChangeTitle . bind ( this ) ;
@@ -23,7 +24,7 @@ export default class Tutorial extends Component {
2324 }
2425
2526 componentDidMount ( ) {
26- this . getTutorial ( this . props . match . params . id ) ;
27+ this . getTutorial ( this . props . router . params . id ) ;
2728 }
2829
2930 onChangeTitle ( e ) {
@@ -106,7 +107,7 @@ export default class Tutorial extends Component {
106107 TutorialDataService . delete ( this . state . currentTutorial . id )
107108 . then ( response => {
108109 console . log ( response . data ) ;
109- this . props . history . push ( '/tutorials' )
110+ this . props . router . navigate ( '/tutorials' ) ;
110111 } )
111112 . catch ( e => {
112113 console . log ( e ) ;
@@ -193,3 +194,5 @@ export default class Tutorial extends Component {
193194 ) ;
194195 }
195196}
197+
198+ export default withRouter ( Tutorial ) ;
Original file line number Diff line number Diff line change 11import React from "react" ;
2- import ReactDOM from "react-dom" ;
2+ import { createRoot } from "react-dom/client " ;
33import { BrowserRouter } from "react-router-dom" ;
44
55import App from "./App" ;
66import * as serviceWorker from "./serviceWorker" ;
77
8- ReactDOM . render (
8+ const container = document . getElementById ( "root" ) ;
9+ const root = createRoot ( container ) ;
10+
11+ root . render (
912 < BrowserRouter >
1013 < App />
11- </ BrowserRouter > ,
12- document . getElementById ( "root" )
14+ </ BrowserRouter >
1315) ;
1416
1517serviceWorker . unregister ( ) ;
You can’t perform that action at this time.
0 commit comments