From dcc56b457749c16c29b6eacc3844ea4db8847860 Mon Sep 17 00:00:00 2001 From: hamster1963 <1410514192@qq.com> Date: Mon, 30 Sep 2024 23:30:34 +0800 Subject: [PATCH] perf: static rendering --- app/[locale]/(main)/page.tsx | 8 +++++++- app/[locale]/layout.tsx | 13 ++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/app/[locale]/(main)/page.tsx b/app/[locale]/(main)/page.tsx index 1f4cdb6..4de86cc 100644 --- a/app/[locale]/(main)/page.tsx +++ b/app/[locale]/(main)/page.tsx @@ -1,7 +1,13 @@ +import { unstable_setRequestLocale } from "next-intl/server"; import ServerList from "../../../components/ServerList"; import ServerOverview from "../../../components/ServerOverview"; -export default function Home() { +export default function Home({ + params: { locale }, +}: { + params: { locale: string }; +}) { + unstable_setRequestLocale(locale); return (
diff --git a/app/[locale]/layout.tsx b/app/[locale]/layout.tsx index 6b89ea5..f53c433 100644 --- a/app/[locale]/layout.tsx +++ b/app/[locale]/layout.tsx @@ -11,6 +11,8 @@ import { Inter as FontSans } from "next/font/google"; import { ThemeProvider } from "next-themes"; import { Viewport } from "next"; import { cn } from "@/lib/utils"; +import { locales } from "@/i18n-metadata"; +import { unstable_setRequestLocale } from "next-intl/server"; const fontSans = FontSans({ subsets: ["latin"], @@ -35,7 +37,10 @@ export const viewport: Viewport = { userScalable: false, }; -export const dynamic = "force-static"; +// export const dynamic = "force-static"; +export async function generateStaticParams() { + return locales.map((locale) => ({ locale })); +} export default function LocaleLayout({ children, @@ -44,12 +49,14 @@ export default function LocaleLayout({ children: React.ReactNode; params: { locale: string }; }) { + unstable_setRequestLocale(locale); + const messages = useMessages(); return ( - {/* + - */} +