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

70
Visualizações
Dynamic links Navbar

I am interested in making a dynamic Navbar fetching datas from mongodb.

This is my structure :

# src

* [components/]
  * [Navbar.js]]
  * [Layout.js]]
* [pages/]
  * [index.js]
  * [_app.js]

Though it is not possible to getServerSideProps inside of Components if I am not mistaken, nor inside of _app.js.

I've heard of getInitialProps but I haven't been able to wrap my head around it and also it would lead into a nasty prop drilling.

_app.js -> Layout -> Navbar

Now, how would you do a Navbar with dynamics links according to what's fetched from mondodb?

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

0

I think nextJs has a documentation on this topic. https://nextjs.org/docs/basic-features/pages

export async function getStaticPaths() {
  // Call an external API endpoint to get posts
  const res = await fetch('https://.../mongodb')
  const posts = await res.json()

  // Get the paths we want to pre-render based on posts
  const paths = posts.map((post) => ({
    params: { id: post.id },
  }))

  // We'll pre-render only these paths at build time.
  // { fallback: false } means other routes should 404.
  return { paths, fallback: false }
}

The idea is to generate a list of paths. But your mongodb needs to be called in the compile time, not runtime.

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