Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

275
Visualizações
How to map from API call to params in getStaticPaths?

I'm trying to map params into Next.js getStaticPaths but it doesn't work. Below you can see it works.

enter image description here

But it doesn't work as soon as want to add one more field which is the slug of the article.

The routing looks something like this. index>[username]>[slug] <=== slug is for article.

To simplify the code, the API looks like this.

[
 {
  id
  username
  email
 },
 articles: [
   [Object], [Object], [Object],
  ]
 }
]

And inside articles array looks something like this:

articles: [
 {
  id
  title
  description
  slug
 }
]

How do I make it work? How to map username and article's slug to param so that it works?

Edit: I want to have username slug and article slug together so that I can have www.com/[username]/[articleSlug].

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I'm not sure I understood your issue very well, but you just use getStaticPaths to generate the article url like this:

export async function getStaticPaths() {
  const articles = await fetchAPI("/articles")

  return {
    paths: articles.map((article) => ({
      params: {
        slug: article.slug,
      },
    })),
    fallback: false,
  }
}

Then to get the user and the article data you can use getStaticProps like this:

export async function getStaticProps({ params }) {
  const article = (await fetchAPI(`/articles?slug=${params.slug}`))[0]
  const users = await fetchAPI("/users")

  return {
    props: { article, users },
    revalidate: 1,
  }
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda