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); 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 }) { // 🔴 修复:params 是同步对象,移除不必要的 await const { locale, slug } = await params; const line = await getLine(locale, slug); if (!line) return
404 - 产线不存在
; return (
{/* 标题 */}

{line.title}

{/* 产品描述 */}

{line.desc}

{/* 封面图 */} {line.cover && (
{`${line.title}
)} {/* 产品图片列表 */} {line.images && line.images.length > 0 && (

产品图片

{line.images.map((imgUrl, index) => (
{`${line.title}
))}
)} {/* 产品特性/参数 */} {line.properties && line.properties.length > 0 && (

产品参数

    {line.properties.map((prop, index) => (
  • {/* 处理参数中的换行符 \n */} "), }} />
  • ))}
)}
); } 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 []; } }