Files
fad-trade-next/components/header/HeaderLinks.tsx
砂糖 216076ff2a feat: 重构导航和博客系统,支持多级菜单和API数据源
- 重构导航菜单支持多级子菜单结构
- 博客系统改为从API获取数据,移除本地文件存储
- 删除旧的关于页面,准备重构
- 修复博客详情页slug匹配问题
- 默认首页重定向到中文版本
2025-11-21 17:49:17 +08:00

54 lines
1.8 KiB
TypeScript

"use client";
import { Link as I18nLink, usePathname, useRouter } from "@/i18n/routing";
import { cn } from "@/lib/utils";
import { HeaderLink } from "@/types/common";
import { useTranslations } from "next-intl";
const HeaderLinks = () => {
const tHeader = useTranslations("Header");
const pathname = usePathname();
const router = useRouter();
const headerLinks: HeaderLink[] = tHeader.raw("links");
const localePrefix = `/${(pathname || "/zh").split("/")[1] || "zh"}`;
return (
<div className="hidden md:flex flex-row items-center gap-x-2 text-sm font-medium text-muted-500">
{headerLinks.map((link) => {
return (
<div key={link.name} className="relative group">
<I18nLink
href={link.href}
title={link.name}
prefetch={true}
className={cn(
"rounded-xl px-4 py-2 flex items-center gap-x-1 hover:bg-accent-foreground/10 hover:text-accent-foreground",
pathname === link.href && "font-semibold text-accent-foreground"
)}
>
{link.name}
</I18nLink>
{
link?.children && (
<div className="absolute left-0 top-full hidden group-hover:block z-50 pt-2">
<div className="w-56 rounded-md border bg-white shadow-md overflow-hidden">
{link.children.map((child) => (
<I18nLink key={child.name} prefetch={false} href={child.href} className="block px-4 py-2 hover:bg-red-600 hover:text-white">
{child.name}
</I18nLink>
))}
</div>
</div>
)
}
</div>
);
})}
</div>
);
};
export default HeaderLinks;