From 7d5e2d664c75a9c2593d35843e48a5c72d3d7f42 Mon Sep 17 00:00:00 2001 From: Harsh Wardhan Date: Wed, 17 Jun 2026 23:01:57 +0530 Subject: [PATCH] Refactor routing and component imports in App.js --- client/src/App.js | 154 ++++++++++++++++++++++++---------------------- 1 file changed, 80 insertions(+), 74 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index b1205b0..f0d08ce 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -1,8 +1,16 @@ import React from "react"; import { ThemeProvider } from "./theme/ThemeProvider"; -import { BrowserRouter as Router, Routes, Route, useLocation } from "react-router-dom"; +import { + BrowserRouter as Router, + Routes, + Route, + useLocation, +} from "react-router-dom"; + import { AuthProvider } from "./context/AuthContext"; import Navbar from "./components/Navbar"; +import ScrollToTop from "./components/scrolltotop"; +import ProtectedRoute from "./components/ProtectedRoute"; import Home from "./pages/Home"; import Syllabus from "./pages/Syllabus"; import Notes from "./pages/Notes"; @@ -14,92 +22,85 @@ import Contact from "./pages/Contact"; import Analytics from "./pages/Analytics"; import Faq from "./pages/Faq"; import Contribute from "./pages/Contribute"; -import ScrollToTop from "./components/scrolltotop"; import MindMapEditor from "./pages/MindMapEditor"; -import Profile from "./pages/Profile.js"; +import Profile from "./pages/Profile"; import SubmitFeedback from "./pages/SubmitFeedback"; import Todo from "./pages/Todo"; import Login from "./pages/Login"; import Register from "./pages/Register"; -import ProtectedRoute from "./components/ProtectedRoute"; +import NotFound from "./pages/NotFound"; + +const PageLayout = ({ children }) => ( +
+ {children} +
+); + +const ProtectedPage = ({ children }) => ( + + {children} + +); + +const protectedRoutes = [ + { path: "/tasks", element: }, + { path: "/syllabus", element: }, + { path: "/notes", element: }, + { path: "/pyqs", element: }, + { path: "/analytics", element: }, + { path: "/faq", element: }, + { path: "/feedback", element: }, + { path: "/contribute", element: }, + { path: "/mindmap", element: }, + { path: "/contact", element: }, + { path: "/profile", element: }, + { path: "/feedback/submit", element: }, +]; const App = () => { return ( - {/* Navbar is hidden on login/register via CSS — it checks the route */} + - {/* ── Public routes ── */} - } /> + } /> + } /> } /> -
} /> -
} /> - {/* ── Public landing page ── */} - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> - -
- - } /> + + + + } + /> + + + + + } + /> + + {protectedRoutes.map((route) => ( + + {route.element} + + } + /> + ))} + + } />
@@ -107,11 +108,16 @@ const App = () => { ); }; -// Hide Navbar on login/register pages const NavbarWrapper = () => { const { pathname } = useLocation(); - if (pathname === "/login" || pathname === "/register") return null; + + const hiddenRoutes = ["/login", "/register"]; + + if (hiddenRoutes.includes(pathname)) { + return null; + } + return ; }; -export default App; \ No newline at end of file +export default App;