Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

223
Vistas
Return two values from getStaticPaths

I'm using getStaticPaths to create a product page within NextJS. I get my products from wooCommerce, problem is:

I want to use "permalink" for my NextJS route URL, but I need product.id to get data for that particular product that is being rendered.

My code looks something like this:

export async function getStaticPaths() {
    const res = await fetch('https://.../products/')
    const products = await res.json()
    const paths = products.map((product) => ({
      params: { permalink: product.slug, id: product.id},
    }))
    return { paths, fallback: false }
  }
  

  export async function getStaticProps({params}) {
    console.log(params);
    const res = await fetch(`https://.../products/${params.id}`)
    const productsData = await res.json()
  
    return { props: { productsData } }
  }

I'm trying to pass id in params, but NextJS only expects variables that is in JS filename (in this case, [permalink].js) so ID is not being passed down to getStaticProps, and I need ID to get product data since API doesn't work with permalink.

Is there any way I can pass another variable (ID in this case) from getStaticPaths to getStaticProps?

about 4 years ago · Santiago Gelvez
2 Respuestas
Responde la pregunta

0

export async function getStaticPaths() {
   const res = await fetch('https://.../products/')
   const products = await res.json()
   let paths = []
    
   for (const product of products){
      paths.push({params: {permalink: product.slug }, id: product.your_map_id})

   }
   return { paths, fallback: false }
}
about 4 years ago · Santiago Gelvez Denunciar

0

You need to create a nested dynamic route. page/[permalink]/[id].js

about 4 years ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda