Files
sage-home/app/[locale]/single/page.tsx
砂糖 70f337bb92 init
2026-01-24 16:54:44 +08:00

66 lines
1.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { LOCALES } from "@/i18n/routing";
import { getLines } from "@/lib/lines";
import { constructMetadata } from "@/lib/metadata";
import { Line } from "@/types/line";
import { Metadata } from "next";
import { getTranslations } from "next-intl/server";
// 强制静态生成
export const dynamic = "force-static";
// 明确 Params 类型(静态生成的参数)
type Params = { locale: string };
type MetadataProps = {
params: Params;
};
// 生成页面元数据(确保服务端/客户端翻译一致)
export async function generateMetadata({
params,
}: MetadataProps): Promise<Metadata> {
const { locale } = params;
const t = await getTranslations({ locale, namespace: "Workshop" });
return constructMetadata({
page: "Workshop",
title: t("pageTitle", { defaultValue: "车间展示" }), // 使用 next-intl 官方的 defaultValue
description: t("pageDesc", { defaultValue: "公司产品线展示" }),
locale: locale,
path: `/line`,
canonicalUrl: `/line`,
});
}
// 生成静态路由参数(多语言)
export async function generateStaticParams() {
return LOCALES.map((locale) => ({
locale,
}));
}
// 空数据组件(纯静态,无动态属性)
function EmptyState() {
return <div className="py-10 text-center text-gray-500">线</div>;
}
// 单个车间卡片组件Client Component 标记,避免 Hydration 冲突)
// 'use client'; // 仅当需要添加交互时启用,当前纯展示可不用
function ProductCard({ product }: { product: Line }) {
}
// 页面主组件Server Component
export default async function Page({
params,
}: {
params: Params;
}) {
const { locale } = await params;
// 获取翻译(确保服务端/客户端一致)
const t = await getTranslations({ locale, namespace: "Workshop" });
// 获取产品线数据(顶层 awaitServer Component 原生支持)
const products: Line[] = await getLines(locale);
}