Fetch Loop for static generated page
Unanswered
Green-tailed Towhee posted this in #help-forum
Green-tailed TowheeOP
generated this /locale/products/:id -> during the build time using the generateStaticParams
But when I visit the page , I see way too many get request on same page/product , anyone got any idea , what would be the cause for this ?
My Code :
But when I visit the page , I see way too many get request on same page/product , anyone got any idea , what would be the cause for this ?
My Code :
ts
export async function generateStaticParams() {
const products = await prisma.product.findMany({});
const locales = ["en", "ar"];
const paths: { id: string; locale: string }[] = [];
products.map((prod) => {
locales.forEach((locale) => {
paths.push({ locale, id: prod.id });
});
});
return paths;
}
export async function generateMetadata({
params: { id, locale },
}: {
params: { id: string; locale: string };
}) {
const product = await prisma.product.findFirst({
where: { id },
include: { category: true },
});
return {
title: locale === "en" ? product?.title : product?.ar_title,
};
}
const page = async ({ params }: { params: { id: string; locale: string } }) => {
const locale = params.locale;
unstable_setRequestLocale(locale);
const product = await prisma.product.findFirst({
where: { id: params.id },
include: { category: true },
});
if (!product) {
return <div>Not Found Page</div>;
}
return <div>singleproduct</div>