Skip to content

Commit 96cb4bb

Browse files
authored
feat: Add React Router (#16)
* feat: Add React Router * merged from app.tsx from main * integrate existing frontend template with router
1 parent eaecb39 commit 96cb4bb

File tree

8 files changed

+158
-24
lines changed

8 files changed

+158
-24
lines changed

web/package-lock.json

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

web/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"@tailwindcss/vite": "^4.1.4",
1515
"react": "^19.0.0",
1616
"react-dom": "^19.0.0",
17+
"react-router-dom": "^7.5.0",
1718
"react-icons": "^5.5.0",
1819
"tailwindcss": "^4.1.4"
1920
},

web/src/App.tsx

+10-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1+
import { useEffect, useState } from "react";
2+
import { Outlet } from "react-router-dom";
13
import SideNav from "./components/SideNav";
2-
import PopularActivities from "./components/PopularActivities";
3-
import WeeklySchedule from "./components/WeeklySchedule";
44
import RightContent from "./components/RightContent";
5-
import PersonalBests from "./components/PersonalBests";
5+
// function App() {
6+
// return (
7+
// <>
8+
// {/* This is where the Navbar and other components will be rendered */}
9+
//
10+
// </>
611

712
export default function App() {
813
return (
@@ -11,17 +16,8 @@ export default function App() {
1116
<div className="flex-shrink-0">
1217
<SideNav />
1318
</div>
14-
<div className="flex flex-col flex-1 w-full p-4 md:p-8 overflow-y-auto min-h-0">
15-
<PopularActivities />
16-
<div className="flex flex-col md:flex-row gap-4 md:gap-8 mt-8">
17-
<div className="w-full md:w-1/2">
18-
<WeeklySchedule />
19-
</div>
20-
<div className="w-full md:w-1/2">
21-
<PersonalBests />
22-
</div>
23-
</div>
24-
</div>
19+
<Outlet />{" "}
20+
{/* This is where the Content (child routes) will be rendered */}
2521
<div className="w-full md:w-64 p-4 flex-shrink-0 overflow-y-auto min-h-0">
2622
<RightContent />
2723
</div>

web/src/components/SideNav.tsx

+14-7
Original file line numberDiff line numberDiff line change
@@ -32,54 +32,61 @@ const SideNav: React.FC = () => {
3232
TTP Code App
3333
</div>
3434
<a
35-
href="#home"
35+
href="/"
3636
className="text-base md:text-lg p-2 md:p-0"
3737
onClick={toggleMenu}
3838
>
3939
Home
4040
</a>
4141
<a
42-
href="#profile"
42+
href="#profile" //update this to the correct route
4343
className="text-base md:text-lg p-2 md:p-0"
4444
onClick={toggleMenu}
4545
>
4646
Profile
4747
</a>
4848
<a
49-
href="#schedule"
49+
href="#schedule" //update this to the correct route
5050
className="text-base md:text-lg p-2 md:p-0"
5151
onClick={toggleMenu}
5252
>
5353
Schedule
5454
</a>
5555
<a
56-
href="#activities"
56+
href="#activities" //update this to the correct route
5757
className="text-base md:text-lg p-2 md:p-0"
5858
onClick={toggleMenu}
5959
>
6060
Activities
6161
</a>
6262
<a
63-
href="#settings"
63+
href="#settings" //update this to the correct route
6464
className="text-base md:text-lg p-2 md:p-0"
6565
onClick={toggleMenu}
6666
>
6767
Settings
6868
</a>
6969
<a
70-
href="#quiz"
70+
href="#quiz" //update this to the correct route
7171
className="text-base md:text-lg p-2 md:p-0"
7272
onClick={toggleMenu}
7373
>
7474
Quiz
7575
</a>
7676
<a
77-
href="#leetcode"
77+
href="#leetcode" //update this to the correct route
7878
className="text-base md:text-lg p-2 md:p-0"
7979
onClick={toggleMenu}
8080
>
8181
Leetcode
8282
</a>
83+
<a
84+
href="/about" //update this to the correct route
85+
className="text-base md:text-lg p-2 md:p-0"
86+
onClick={toggleMenu}
87+
>
88+
About Us
89+
</a>
8390
</div>
8491

8592
{isOpen && (

web/src/main.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
33
import "./index.css";
4-
import App from "./App.tsx";
4+
import { RouterProvider } from "react-router-dom";
5+
import { router } from "./router.js";
56

67
createRoot(document.getElementById("root")!).render(
78
<StrictMode>
8-
<App />
9-
</StrictMode>,
9+
<RouterProvider router={router} />
10+
</StrictMode>
1011
);

web/src/pages/AboutUs.tsx

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from "react";
2+
3+
const AboutUs = () => {
4+
return (
5+
<div>
6+
<h1>About Us</h1>
7+
<p>
8+
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod
9+
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim
10+
veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
11+
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate
12+
velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
13+
occaecat cupidatat non proident, sunt in culpa qui officia deserunt
14+
mollit anim id est laborum.
15+
</p>
16+
</div>
17+
);
18+
};
19+
20+
export default AboutUs;

web/src/pages/Home.tsx

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React from "react";
2+
import PopularActivities from "../components/PopularActivities";
3+
import WeeklySchedule from "../components/WeeklySchedule";
4+
5+
import PersonalBests from "../components/PersonalBests";
6+
7+
const Home = () => {
8+
return (
9+
<div>
10+
<div className="flex flex-col flex-1 w-full p-4 md:p-8 overflow-y-auto min-h-0">
11+
<PopularActivities />
12+
<div className="flex flex-col md:flex-row gap-4 md:gap-8 mt-8">
13+
<div className="w-full md:w-1/2">
14+
<WeeklySchedule />
15+
</div>
16+
<div className="w-full md:w-1/2">
17+
<PersonalBests />
18+
</div>
19+
</div>
20+
</div>
21+
</div>
22+
);
23+
};
24+
25+
export default Home;

web/src/router.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { createBrowserRouter } from "react-router-dom";
2+
import App from "./App.tsx";
3+
4+
import AboutUs from "./pages/AboutUs.tsx";
5+
import Home from "./pages/Home.tsx";
6+
export const router = createBrowserRouter([
7+
{
8+
path: "/",
9+
element: <App />,
10+
11+
children: [
12+
{ path: "about", element: <AboutUs /> },
13+
{ path: "/", element: <Home /> },
14+
],
15+
},
16+
]);

0 commit comments

Comments
 (0)