import { LOCALES } from "@/i18n/routing"; import { getLine, getLines } from "@/lib/lines"; import { constructMetadata } from "@/lib/metadata"; import { Line } from "@/types/line"; import { Metadata } from "next"; import { Locale } from "next-intl"; // 强制静态渲染 export const dynamic = "force-static"; // 固定 Params 类型为普通对象(Next.js 原生传参无异步) type Params = { locale: string; slug: string; }; type MetadataProps = { params: Params; }; export async function generateMetadata({ params, }: MetadataProps): Promise { const { locale, slug } = await params; const line = await getLine(locale, slug); console.log(line); console.log(line?.slug); if (!line) { return constructMetadata({ title: "404 - 产线不存在", description: "请求的产线页面未找到", noIndex: true, locale: locale as Locale, path: `/line/${slug}`, canonicalUrl: `/line/${slug}`, }); } return constructMetadata({ title: line.title, description: line.desc, locale: locale as Locale, path: `/line/${slug}`, canonicalUrl: `/line/${slug}`, }); } // 页面主组件 - 仅保留字段展示+修复 Hydration 错误 export default async function ProductDetailPage({ params }: { params: Params }) { // 🔴 核心修复1:移除不必要的 await(params 是同步对象) const { locale, slug } = await params; const line = await getLine(locale, slug); if (!line) return null; // 兜底处理:避免字段为空导致属性不匹配 const coverSrc = line.cover || ""; const coverAlt = line.title || "产线封面"; const lineDesc = line.desc || "暂无产线描述"; return (
{/* 封面图区域 - 🔴 修复布局属性不一致 */}
{coverAlt}
{/* 标题+描述区域 */}

{line.title}

{lineDesc}

{line.images.length > 0 && (

车间图片

{line.images.map((img, index) => { const stableKey = `line-${slug}-img-${index}-${img.slice(-8)}`; const imgAlt = `${line.title}-图片${index + 1}`; return (
{imgAlt}
); })}
)}
); } export async function generateStaticParams() { try { const defaultLocale = LOCALES[0]; const workShops: Line[] = await getLines(defaultLocale); return LOCALES.flatMap((locale) => workShops.map((workShop) => ({ locale, slug: workShop.slug as string, })) ); } catch (error) { console.error("生成产品静态参数失败:", error); return []; } }