"use client"; import Link from "next/link"; import { usePathname } from "next/navigation"; import { useSession } from "next-auth/react"; import { cn } from "@/lib/cn"; import { useLoginModalStore } from "@/lib/login-modal-store"; const NAV_ITEMS: Array<{ label: string; href: string; /** 若 true,未登录时点击会拦截并弹出登录弹窗 */ requireAuth?: boolean; }> = [ { label: "首页", href: "/" }, { label: "排行榜", href: "/ranking" }, { label: "我的", href: "/me", requireAuth: true }, ]; interface NavLinksProps { className?: string; mobile?: boolean; } export default function NavLinks({ className, mobile = false }: NavLinksProps) { const pathname = usePathname(); const { status } = useSession(); const openLogin = useLoginModalStore((s) => s.show); const isActive = (href: string) => { if (href === "/") return pathname === "/"; return pathname.startsWith(href); }; const handleClick = ( e: React.MouseEvent, item: (typeof NAV_ITEMS)[number], ) => { if (item.requireAuth && status !== "authenticated") { e.preventDefault(); // 登录成功后直接跳目标页面(如「我的」→ /me),不回首页 if (status === "unauthenticated") openLogin(item.href); } }; if (mobile) { return ( ); } return ( ); }