From 3e3d7686f64f5919f08cdac65d4b1c5d255e7289 Mon Sep 17 00:00:00 2001 From: Vishesh 'ironeagle' Bangotra Date: Sat, 4 Apr 2026 13:53:21 +0530 Subject: [PATCH] header fixes --- src/Header.tsx | 19 ++++++++++++++++--- src/main.jsx | 25 +++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Header.tsx b/src/Header.tsx index c93ccee..51d6824 100644 --- a/src/Header.tsx +++ b/src/Header.tsx @@ -1,4 +1,8 @@ import * as React from "react"; +import { + useLocation, + matchPath +} from "react-router-dom"; import { AppBar, Toolbar, @@ -16,14 +20,23 @@ import { useNavigate } from "react-router-dom"; import { useAuth } from "../react-auth"; interface HeaderProps { - headerTitle: string; - onDrawerToggle?: () => void; // optional (only used where needed) + routerMapping: { + path: string; + headerTitle: string; + }[]; + onDrawerToggle?: () => void; } export default function Header({ - headerTitle, + routerMapping, onDrawerToggle, }: HeaderProps) { + const location = useLocation(); + const matchedRoute = routerMapping.find((route) => + matchPath({ path: route.path, end: false }, location.pathname) + ); + const headerTitle = matchedRoute?.headerTitle ?? "Khata"; + const navigate = useNavigate(); const { currentUser, logout } = useAuth(); diff --git a/src/main.jsx b/src/main.jsx index 875ba8c..c27071a 100644 --- a/src/main.jsx +++ b/src/main.jsx @@ -27,21 +27,38 @@ const rootElement = document.getElementById('root'); const root = createRoot(rootElement); const AUTH_BASE = import.meta.env.VITE_AUTH_BASE_URL; +const routerMapping = [ + { path: "/", component: Home, headerTitle: "Home" }, + { path: "/home", component: Home, headerTitle: "Home" }, + { path: "/admin/*", component: Admin, headerTitle: "Admin" }, +]; + root.render( -
+
- } /> - } /> - } /> + {routerMapping.map(({ path, component: Component }) => ( + + ) : ( + + ) + } + /> + ))} +