File tree Expand file tree Collapse file tree 7 files changed +6526
-22039
lines changed Expand file tree Collapse file tree 7 files changed +6526
-22039
lines changed Load Diff This file was deleted.
Original file line number Diff line number Diff line change 3
3
"version" : " 0.1.0" ,
4
4
"private" : true ,
5
5
"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 "
15
15
},
16
16
"scripts" : {
17
17
"start" : " react-scripts start" ,
Original file line number Diff line number Diff line change 1
1
import React , { Component } from "react" ;
2
- import { Switch , Route , Link } from "react-router-dom" ;
2
+ import { Routes , Route , Link } from "react-router-dom" ;
3
3
import "bootstrap/dist/css/bootstrap.min.css" ;
4
4
import "./App.css" ;
5
5
@@ -30,11 +30,12 @@ class App extends Component {
30
30
</ nav >
31
31
32
32
< 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 >
38
39
</ div >
39
40
</ div >
40
41
) ;
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 1
1
import React , { Component } from "react" ;
2
2
import TutorialDataService from "../services/tutorial.service" ;
3
+ import { withRouter } from '../common/with-router' ;
3
4
4
- export default class Tutorial extends Component {
5
+ class Tutorial extends Component {
5
6
constructor ( props ) {
6
7
super ( props ) ;
7
8
this . onChangeTitle = this . onChangeTitle . bind ( this ) ;
@@ -23,7 +24,7 @@ export default class Tutorial extends Component {
23
24
}
24
25
25
26
componentDidMount ( ) {
26
- this . getTutorial ( this . props . match . params . id ) ;
27
+ this . getTutorial ( this . props . router . params . id ) ;
27
28
}
28
29
29
30
onChangeTitle ( e ) {
@@ -106,7 +107,7 @@ export default class Tutorial extends Component {
106
107
TutorialDataService . delete ( this . state . currentTutorial . id )
107
108
. then ( response => {
108
109
console . log ( response . data ) ;
109
- this . props . history . push ( '/tutorials' )
110
+ this . props . router . navigate ( '/tutorials' ) ;
110
111
} )
111
112
. catch ( e => {
112
113
console . log ( e ) ;
@@ -193,3 +194,5 @@ export default class Tutorial extends Component {
193
194
) ;
194
195
}
195
196
}
197
+
198
+ export default withRouter ( Tutorial ) ;
Original file line number Diff line number Diff line change 1
1
import React from "react" ;
2
- import ReactDOM from "react-dom" ;
2
+ import { createRoot } from "react-dom/client " ;
3
3
import { BrowserRouter } from "react-router-dom" ;
4
4
5
5
import App from "./App" ;
6
6
import * as serviceWorker from "./serviceWorker" ;
7
7
8
- ReactDOM . render (
8
+ const container = document . getElementById ( "root" ) ;
9
+ const root = createRoot ( container ) ;
10
+
11
+ root . render (
9
12
< BrowserRouter >
10
13
< App />
11
- </ BrowserRouter > ,
12
- document . getElementById ( "root" )
14
+ </ BrowserRouter >
13
15
) ;
14
16
15
17
serviceWorker . unregister ( ) ;
You can’t perform that action at this time.
0 commit comments