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

167
Views
NextJS - Obtener variable dinámica en getStaticProps

Así que tengo getStaticProps y necesito hacer una búsqueda de datos basada en una variable aquí hay un ejemplo

 export async function getStaticProps() { const res = await fetch(localWordpressUrl, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ query: ` query AllPostsQuery { posts(where: {categoryName: "blog"}) { nodes { slug content title } } } `, }) }); const json = await res.json(); return { props: { posts: json.data.posts, } }; }

Donde categoryName: "blog" debe ser una variable en lugar de codificada. Sé que puedes conseguir la babosa, pero lo que necesito es antes de la babosa. es decir, site.com/blog/slug. ¿Alguna sugerencia sobre esto?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

De hecho, estás muy cerca. Lo que necesita es tomar el contexto de su función getStaticProps . Agregue esto a su función getStaticProps y mire el console log para ver qué está sucediendo.

 export async function getStaticProps(context) { console.log(JSON.stringify(context, null, 3)); const { asPath, req, res, pathname, query } = context; if (req) { let localWordpressURL = req.headers.host; console.log(localWordpressURL); } }
about 4 years ago · Juan Pablo Isaza 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!