mirror of
https://github.com/KivotosRailway/website.git
synced 2026-11-03 11:06:32 +09:00
修改页面标题路由
This commit is contained in:
@@ -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>}
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user