Skip to content

Commit 434ae58

Browse files
committed
update for react-router-dom v6
1 parent d3729dc commit 434ae58

File tree

9 files changed

+4998
-17791
lines changed

9 files changed

+4998
-17791
lines changed

package-lock.json

-14,158
This file was deleted.

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
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.5.0",
11-
"react": "^16.13.1",
12-
"react-dom": "^16.13.1",
13-
"react-router-dom": "^5.2.0",
14-
"react-scripts": "3.4.1",
6+
"@testing-library/jest-dom": "^5.14.1",
7+
"@testing-library/react": "^11.2.7",
8+
"@testing-library/user-event": "^12.8.3",
9+
"axios": "^0.26.1",
10+
"bootstrap": "^4.6.0",
11+
"react": "^17.0.2",
12+
"react-dom": "^17.0.2",
13+
"react-router-dom": "^6.2.2",
14+
"react-scripts": "4.0.3",
1515
"react-validation": "^3.0.7",
1616
"validator": "^13.0.0"
1717
},

src/App.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { useState, useEffect } from "react";
2-
import { Switch, Route, Link } from "react-router-dom";
2+
import { Routes, Route, Link } from "react-router-dom";
33
import "bootstrap/dist/css/bootstrap.min.css";
44
import "./App.css";
55

@@ -13,7 +13,6 @@ import BoardUser from "./components/BoardUser";
1313
import BoardModerator from "./components/BoardModerator";
1414
import BoardAdmin from "./components/BoardAdmin";
1515

16-
// import AuthVerify from "./common/AuthVerify";
1716
import EventBus from "./common/EventBus";
1817

1918
const App = () => {
@@ -115,18 +114,18 @@ const App = () => {
115114
</nav>
116115

117116
<div className="container mt-3">
118-
<Switch>
119-
<Route exact path={["/", "/home"]} component={Home} />
120-
<Route exact path="/login" component={Login} />
121-
<Route exact path="/register" component={Register} />
122-
<Route exact path="/profile" component={Profile} />
123-
<Route path="/user" component={BoardUser} />
124-
<Route path="/mod" component={BoardModerator} />
125-
<Route path="/admin" component={BoardAdmin} />
126-
</Switch>
117+
<Routes>
118+
<Route path="/" element={<Home/>} />
119+
<Route path="/home" element={<Home/>} />
120+
<Route path="/login" element={<Login/>} />
121+
<Route path="/register" element={<Register/>} />
122+
<Route path="/profile" element={<Profile/>} />
123+
<Route path="/user" element={<BoardUser/>} />
124+
<Route path="/mod" element={<BoardModerator/>} />
125+
<Route path="/admin" element={<BoardAdmin/>} />
126+
</Routes>
127127
</div>
128128

129-
{/* <AuthVerify logOut={logOut}/> */}
130129
</div>
131130
);
132131
};

src/common/AuthVerify.js

-28
This file was deleted.

src/components/Login.js

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useState, useRef } from "react";
2+
import { useNavigate } from 'react-router-dom';
23
import Form from "react-validation/build/form";
34
import Input from "react-validation/build/input";
45
import CheckButton from "react-validation/build/button";
@@ -15,7 +16,9 @@ const required = (value) => {
1516
}
1617
};
1718

18-
const Login = (props) => {
19+
const Login = () => {
20+
let navigate = useNavigate();
21+
1922
const form = useRef();
2023
const checkBtn = useRef();
2124

@@ -45,7 +48,7 @@ const Login = (props) => {
4548
if (checkBtn.current.context._errors.length === 0) {
4649
AuthService.login(username, password).then(
4750
() => {
48-
props.history.push("/profile");
51+
navigate("/profile");
4952
window.location.reload();
5053
},
5154
(error) => {

src/components/Register.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const vpassword = (value) => {
4646
}
4747
};
4848

49-
const Register = (props) => {
49+
const Register = () => {
5050
const form = useRef();
5151
const checkBtn = useRef();
5252

src/services/auth.service.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,11 @@ const getCurrentUser = () => {
3333
return JSON.parse(localStorage.getItem("user"));
3434
};
3535

36-
export default {
36+
const AuthService = {
3737
register,
3838
login,
3939
logout,
4040
getCurrentUser,
4141
};
42+
43+
export default AuthService;

src/services/user.service.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ const getAdminBoard = () => {
1919
return axios.get(API_URL + "admin", { headers: authHeader() });
2020
};
2121

22-
export default {
22+
const UserService = {
2323
getPublicContent,
2424
getUserBoard,
2525
getModeratorBoard,
2626
getAdminBoard,
2727
};
28+
29+
export default UserService;

0 commit comments

Comments
 (0)