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

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

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 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!