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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user