Skip to content

Commit fc81e3f

Browse files
committed
first commit
1 parent 8099e0d commit fc81e3f

17 files changed

+184
-115
lines changed

package-lock.json

+58
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"@testing-library/user-event": "^12.8.3",
99
"react": "^17.0.2",
1010
"react-dom": "^17.0.2",
11+
"react-router-dom": "^6.0.2",
1112
"react-scripts": "4.0.3",
1213
"web-vitals": "^1.1.2"
1314
},

src/App.css

-38
This file was deleted.

src/App.js

+29-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,33 @@
1-
import logo from './logo.svg';
2-
import './App.css';
1+
import {
2+
BrowserRouter as Router,
3+
Navigate,
4+
Route,
5+
Routes,
6+
} from "react-router-dom";
37

4-
function App() {
8+
import HomePage from "./pages/HomePage";
9+
import AboutPage from "./pages/AboutPage";
10+
import UsersPage from "./pages/UsersPage";
11+
import UserPage from "./pages/UserPage";
12+
import Navbar from "./components/Navbar";
13+
import DashboardPage from "./pages/DashboardPage";
14+
15+
export default function App() {
516
return (
6-
<div className="App">
7-
<header className="App-header">
8-
<img src={logo} className="App-logo" alt="logo" />
9-
<p>
10-
Edit <code>src/App.js</code> and save to reload.
11-
</p>
12-
<a
13-
className="App-link"
14-
href="https://reactjs.org"
15-
target="_blank"
16-
rel="noopener noreferrer"
17-
>
18-
Learn React
19-
</a>
20-
</header>
21-
</div>
17+
<Router>
18+
<Navbar />
19+
20+
<Routes>
21+
<Route path="/" element={<HomePage />} />
22+
<Route path="/about" element={<AboutPage />} />
23+
<Route path="/users/*" element={<UserPage />} />
24+
<Route path="/users" element={<UsersPage />} />
25+
<Route path="/myusers/" element={<Navigate replace to="/users" />} />
26+
<Route path="/users/:id" element={<UserPage />} />
27+
<Route path="/dashboard/*" element={<DashboardPage />}>
28+
<Route path="welcome" element={<p>Welcome!</p>} />
29+
</Route>
30+
</Routes>
31+
</Router>
2232
);
2333
}
24-
25-
export default App;

src/App.test.js

-8
This file was deleted.

src/components/Navbar.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { NavLink } from "react-router-dom";
2+
import "./navbar.css";
3+
4+
export default function Navbar() {
5+
return (
6+
<div>
7+
<ul>
8+
<li>
9+
<NavLink
10+
to="/"
11+
className={({ isActive }) => (isActive ? "active" : "")}
12+
>
13+
Home
14+
</NavLink>
15+
</li>
16+
<li>
17+
<NavLink
18+
to="/users"
19+
className={({ isActive }) => (isActive ? "active" : "")}
20+
>
21+
Users
22+
</NavLink>
23+
</li>
24+
<li>
25+
<NavLink
26+
className={({ isActive }) => (isActive ? "active" : "")}
27+
to="/about"
28+
>
29+
About
30+
</NavLink>
31+
</li>
32+
</ul>
33+
</div>
34+
);
35+
}

src/components/navbar.css

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.active {
2+
color: red;
3+
font-weight: bold;
4+
}

src/index.css

-13
This file was deleted.

src/index.js

+4-16
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
import React from 'react';
2-
import ReactDOM from 'react-dom';
3-
import './index.css';
4-
import App from './App';
5-
import reportWebVitals from './reportWebVitals';
1+
import React from "react";
2+
import ReactDOM from "react-dom";
3+
import App from "./App";
64

7-
ReactDOM.render(
8-
<React.StrictMode>
9-
<App />
10-
</React.StrictMode>,
11-
document.getElementById('root')
12-
);
13-
14-
// If you want to start measuring performance in your app, pass a function
15-
// to log results (for example: reportWebVitals(console.log))
16-
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
17-
reportWebVitals();
5+
ReactDOM.render(<App />, document.getElementById("root"));

src/logo.svg

-1
This file was deleted.

src/pages/AboutPage.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import React from 'react'
2+
export default function AboutPage() {
3+
return (
4+
<div>
5+
About
6+
</div>
7+
)
8+
}

src/pages/DashboardPage.js

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Link, Outlet, useNavigate } from "react-router-dom";
2+
3+
export default function DashboardPage() {
4+
const navigate = useNavigate();
5+
6+
const handleClick = () => {
7+
navigate("/");
8+
};
9+
10+
return (
11+
<div>
12+
<h1>Dashboard</h1>
13+
14+
<Link to="welcome">Say Welcome</Link>
15+
16+
<Outlet />
17+
18+
<button onClick={handleClick}>Logout</button>
19+
</div>
20+
);
21+
}

src/pages/HomePage.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react'
2+
3+
export default function HomePage() {
4+
return (
5+
<div>
6+
Home Page
7+
</div>
8+
)
9+
}

src/pages/UserPage.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { useParams } from "react-router-dom";
2+
3+
export default function UserPage() {
4+
const params = useParams();
5+
6+
return (
7+
<div>
8+
User <h1>{params.id}</h1>
9+
</div>
10+
);
11+
}

src/pages/UsersPage.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import React from 'react'
2+
export default function UsersPage() {
3+
return <div>Users</div>;
4+
}

src/reportWebVitals.js

-13
This file was deleted.

src/setupTests.js

-5
This file was deleted.

0 commit comments

Comments
 (0)