revalidate doesn’t seem to work with generateStaticParams in nextJS 14

I have a headless nextjs app with strapi on next 14 with the app router. I’m using output:export to statically export my app on ngnix server. I had some problems to generate the static files for the dynamic routes. I solved it by using a client component to fetch the product data, so I separated the logic into 2 files :

page.tsx :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import { getStrapiData } from "app/api/api"
import ProductPage from "."
// Generate static parameters
export const revalidate = 60
export async function generateStaticParams() {
try {
// Fetch product data from the API
const { data: products } = await getStrapiData("/api/products")
// Map product IDs to static paths
return products.map((product) => ({
slug: product.slug,
}))
} catch (error) {
console.error("Error fetching product IDs:", error)
return [] // Return an empty array in case of an error
}
}
// Multiple versions of this page will be statically generated
// using the `params` returned by `generateStaticParams`
export default function ServerPage({ params }: { params: { slug: string } }) {
return <ProductPage params={{ slug: params.slug }} />
}
</code>
<code>import { getStrapiData } from "app/api/api" import ProductPage from "." // Generate static parameters export const revalidate = 60 export async function generateStaticParams() { try { // Fetch product data from the API const { data: products } = await getStrapiData("/api/products") // Map product IDs to static paths return products.map((product) => ({ slug: product.slug, })) } catch (error) { console.error("Error fetching product IDs:", error) return [] // Return an empty array in case of an error } } // Multiple versions of this page will be statically generated // using the `params` returned by `generateStaticParams` export default function ServerPage({ params }: { params: { slug: string } }) { return <ProductPage params={{ slug: params.slug }} /> } </code>
import { getStrapiData } from "app/api/api"
import ProductPage from "."

// Generate static parameters
export const revalidate = 60
export async function generateStaticParams() {
  try {
    // Fetch product data from the API
    const { data: products } = await getStrapiData("/api/products")
    // Map product IDs to static paths
    return products.map((product) => ({
      slug: product.slug,
    }))
  } catch (error) {
    console.error("Error fetching product IDs:", error)
    return [] // Return an empty array in case of an error
  }
}

// Multiple versions of this page will be statically generated
// using the `params` returned by `generateStaticParams`
export default function ServerPage({ params }: { params: { slug: string } }) {
  return <ProductPage params={{ slug: params.slug }} />
}

index.tsx :

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>"use client"
import { getProductBySlug } from "app/api/api"
import { useEffect, useState } from "react"
import { ProductData } from "types/types"
import Product from "@/components/Product/product"
import ProductDetails from "@/components/Product/productDetails"
import { pathBottom, pathTop } from "@/components/SVG/Stroke"
interface Props {
params: {
slug: string
}
}
export default function ProductPage({ params }: Props) {
const { slug } = params
console.log("Generating page for product slug:", slug)
const [product, setProduct] = useState<ProductData | null>(null)
useEffect(() => {
async function fetchData() {
try {
const response = await getProductBySlug(slug)
const productData = response.data[0] // Accès au premier élément du tableau data
console.log("Product fetched:", productData)
setProduct(productData)
} catch (error) {
console.error("Error fetching product data:", error)
}
}
fetchData()
}, [slug])
if (!product) {
return <div className="mx-auto mt-32 w-screen text-center text-xl text-blue">Chargement...</div> // Handle loading state if needed
}
const { game_bonux } = product
const color = game_bonux?.color
if (!color) {
console.error("Le produit ou sa propriété color est indéfini.")
return <div>Error: Product data incomplete.</div> // Handle error state
}
const svgTop = (
<svg
width="100%"
height="28"
viewBox="0 0 720 28"
preserveAspectRatio="none"
fill={color}
xmlns="http://www.w3.org/2000/svg"
>
{pathTop}
fill={color}
</svg>
)
const svgBottom = (
<svg
width="100%"
height="28"
viewBox="0 0 720 28"
preserveAspectRatio="none"
fill={color}
xmlns="http://www.w3.org/2000/svg"
>
{pathBottom}
fill={color}
</svg>
)
return (
<>
{/* Section Hero */}
<div className="mt-16 hidden md:block">{svgTop}</div>
<Product product={product} color={color} />
<div className="-mt-1 hidden md:block">{svgBottom}</div>
<ProductDetails product={product} />
</>
)
}
</code>
<code>"use client" import { getProductBySlug } from "app/api/api" import { useEffect, useState } from "react" import { ProductData } from "types/types" import Product from "@/components/Product/product" import ProductDetails from "@/components/Product/productDetails" import { pathBottom, pathTop } from "@/components/SVG/Stroke" interface Props { params: { slug: string } } export default function ProductPage({ params }: Props) { const { slug } = params console.log("Generating page for product slug:", slug) const [product, setProduct] = useState<ProductData | null>(null) useEffect(() => { async function fetchData() { try { const response = await getProductBySlug(slug) const productData = response.data[0] // Accès au premier élément du tableau data console.log("Product fetched:", productData) setProduct(productData) } catch (error) { console.error("Error fetching product data:", error) } } fetchData() }, [slug]) if (!product) { return <div className="mx-auto mt-32 w-screen text-center text-xl text-blue">Chargement...</div> // Handle loading state if needed } const { game_bonux } = product const color = game_bonux?.color if (!color) { console.error("Le produit ou sa propriété color est indéfini.") return <div>Error: Product data incomplete.</div> // Handle error state } const svgTop = ( <svg width="100%" height="28" viewBox="0 0 720 28" preserveAspectRatio="none" fill={color} xmlns="http://www.w3.org/2000/svg" > {pathTop} fill={color} </svg> ) const svgBottom = ( <svg width="100%" height="28" viewBox="0 0 720 28" preserveAspectRatio="none" fill={color} xmlns="http://www.w3.org/2000/svg" > {pathBottom} fill={color} </svg> ) return ( <> {/* Section Hero */} <div className="mt-16 hidden md:block">{svgTop}</div> <Product product={product} color={color} /> <div className="-mt-1 hidden md:block">{svgBottom}</div> <ProductDetails product={product} /> </> ) } </code>
"use client"

import { getProductBySlug } from "app/api/api"
import { useEffect, useState } from "react"
import { ProductData } from "types/types"
import Product from "@/components/Product/product"
import ProductDetails from "@/components/Product/productDetails"
import { pathBottom, pathTop } from "@/components/SVG/Stroke"

interface Props {
  params: {
    slug: string
  }
}
export default function ProductPage({ params }: Props) {
  const { slug } = params
  console.log("Generating page for product slug:", slug)

  const [product, setProduct] = useState<ProductData | null>(null)

  useEffect(() => {
    async function fetchData() {
      try {
        const response = await getProductBySlug(slug)
        const productData = response.data[0] // Accès au premier élément du tableau data
        console.log("Product fetched:", productData)
        setProduct(productData)
      } catch (error) {
        console.error("Error fetching product data:", error)
      }
    }
    fetchData()
  }, [slug])

  if (!product) {
    return <div className="mx-auto mt-32 w-screen text-center text-xl text-blue">Chargement...</div> // Handle loading state if needed
  }

  const { game_bonux } = product
  const color = game_bonux?.color

  if (!color) {
    console.error("Le produit ou sa propriété color est indéfini.")
    return <div>Error: Product data incomplete.</div> // Handle error state
  }

  const svgTop = (
    <svg
      width="100%"
      height="28"
      viewBox="0 0 720 28"
      preserveAspectRatio="none"
      fill={color}
      xmlns="http://www.w3.org/2000/svg"
    >
      {pathTop}
      fill={color}
    </svg>
  )

  const svgBottom = (
    <svg
      width="100%"
      height="28"
      viewBox="0 0 720 28"
      preserveAspectRatio="none"
      fill={color}
      xmlns="http://www.w3.org/2000/svg"
    >
      {pathBottom}
      fill={color}
    </svg>
  )

  return (
    <>
      {/* Section Hero */}
      <div className="mt-16 hidden md:block">{svgTop}</div>
      <Product product={product} color={color} />
      <div className="-mt-1 hidden md:block">{svgBottom}</div>
      <ProductDetails product={product} />
    </>
  )
}

It worked but when I add a product in the back office, the params don’t seem to be revalidated, or at least the new routes is leading to a 404 error

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật