Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
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 answers
Answer question

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 Report

0

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

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!