Skip to content

Commit eb323a0

Browse files
committed
feat: enhance static generate
1 parent a273312 commit eb323a0

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

app/[locale]/blog/page.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BlogCard } from "@/app/[locale]/blog/BlogCard";
2-
import { Locale } from "@/i18n/routing";
2+
import { Locale, LOCALES } from "@/i18n/routing";
33
import { getPosts } from "@/lib/getBlogs";
44
import { constructMetadata } from "@/lib/metadata";
55
import { Metadata } from "next";
@@ -45,3 +45,7 @@ export default async function Page({ params }: { params: Params }) {
4545
</div>
4646
);
4747
}
48+
49+
export async function generateStaticParams() {
50+
return LOCALES.map((locale) => ({ locale }));
51+
}

app/[locale]/layout.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ import "@/styles/globals.css";
1414
import "@/styles/loading.css";
1515
import { Analytics } from "@vercel/analytics/react";
1616
import { Metadata, Viewport } from "next";
17-
import { NextIntlClientProvider } from "next-intl";
18-
import { getMessages, getTranslations } from "next-intl/server";
17+
import { hasLocale, NextIntlClientProvider } from "next-intl";
18+
import {
19+
getMessages,
20+
getTranslations,
21+
setRequestLocale,
22+
} from "next-intl/server";
1923
import { ThemeProvider } from "next-themes";
2024
import { notFound } from "next/navigation";
2125

@@ -53,10 +57,12 @@ export default async function LocaleLayout({
5357
const { locale } = await params;
5458

5559
// Ensure that the incoming `locale` is valid
56-
if (!routing.locales.includes(locale as any)) {
60+
if (!hasLocale(routing.locales, locale)) {
5761
notFound();
5862
}
5963

64+
setRequestLocale(locale);
65+
6066
// Providing all messages to the client
6167
// side is the easiest way to get started
6268
const messages = await getMessages();

0 commit comments

Comments
 (0)