Fix browser tab titles on every route

Add usePageTitle so public and admin pages set document.title
to the current page (e.g. Portfolio · jmartgraphix).
This commit is contained in:
2026-07-24 10:56:34 -04:00
parent cef5738044
commit 36c008ac26
7 changed files with 59 additions and 3 deletions
+17 -1
View File
@@ -1,12 +1,28 @@
import { useEffect, useState } from "react";
import { Link, NavLink, Outlet, useNavigate } from "react-router-dom";
import { Link, NavLink, Outlet, useLocation, useNavigate } from "react-router-dom";
import { api } from "../../lib/api";
import { usePageTitle } from "../../lib/pageTitle";
import "./Admin.scss";
function adminTitleFromPath(pathname: string): string {
if (pathname.endsWith("/projects/new")) return "New project · Admin";
if (/\/projects\/[^/]+$/.test(pathname) && !pathname.endsWith("/projects"))
return "Edit project · Admin";
if (pathname.includes("/projects")) return "Projects · Admin";
if (pathname.includes("/categories")) return "Categories · Admin";
if (pathname.includes("/views")) return "Portfolio views · Admin";
if (pathname.includes("/resume")) return "Resume · Admin";
if (pathname.includes("/settings")) return "Settings · Admin";
return "Admin";
}
export function AdminLayout() {
const [user, setUser] = useState<{ username: string; name?: string } | null>(null);
const [error, setError] = useState<string | null>(null);
const navigate = useNavigate();
const location = useLocation();
usePageTitle(adminTitleFromPath(location.pathname));
useEffect(() => {
api