修改页面标题路由

This commit is contained in:
2026-08-22 22:40:25 +08:00
parent 4e778d895b
commit 65322c20c1
11 changed files with 137 additions and 15 deletions
+2 -1
View File
@@ -1,8 +1,9 @@
import Link from "next/link";
import { getLocaleMessages } from "@/lib/i18n";
export function PageBreadcrumb({ items }: { items: Array<{ label: string; href?: string }> }) {
return (
<nav className="page-breadcrumb" aria-label="页面位置">
<nav className="page-breadcrumb" aria-label={getLocaleMessages("zh-CN").common.pagePosition}>
{items.map((item, index) => (
<span className="page-breadcrumb-item" key={`${item.label}-${index}`}>
{index > 0 && <span className="page-breadcrumb-separator" aria-hidden="true">›</span>}
+17 -1
View File
@@ -10,7 +10,23 @@ export function SiteHeader() {
const [menuOpen, setMenuOpen] = useState(false);
useEffect(() => {
const syncLocale = (nextLocale: Locale) => setLocale(nextLocale);
const updateDocumentTitle = (nextLocale: Locale) => {
const messages = getLocaleMessages(nextLocale);
const pathname = window.location.pathname;
const currentTitle = document.title.split(" | ")[0];
const pageLabel = pathname === "/"
? ""
: pathname === "/news"
? messages.common.news
: currentTitle;
document.title = pageLabel ? `${pageLabel} | ${messages.common.siteTitle}` : messages.common.siteTitle;
};
const syncLocale = (nextLocale: Locale) => {
setLocale(nextLocale);
updateDocumentTitle(nextLocale);
};
const handleLocaleChange = (event: Event) => {
const nextLocale = (event as CustomEvent<{ locale?: Locale }>).detail?.locale ?? getInitialLocale();