Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
Next js Dynamic Router misfiring

The following is my folder structure in next js

/pages
|_/index.js
|_/programs
   |_/[program_id].js
   |_/index.js

Both pages have getStaticProps which make a fetch api to pass props to the page; Also /[program_id].js has a getStaticPaths which provides 3 paths,

Question:

When i load https://www.domain/programs it renders. /programs/index.js, from there i click <Link href="/programs/P01"> it renders /programs/[program_id].js page;

But from there when i click <Link href="/programs">, it fires getStaticProps of /programs/index.js but client side it call render function of /programs/[program_id].js where router.query.program_id is undefined

Not sure why this is happening? i was expecting it to call the render for /programs/index.js

/programs/index.js
export async function getStaticProps() {
  const programs = await fetchProgramsList(); //Fetch API
  return {
    props: {
      programs: programs.data,
    },
  };
}
/programs/[program_id].js
export async function getStaticPaths() {
  return {
    paths: [
      { params: { program_id: "P01" } },
      { params: { program_id: "P02" } },
      { params: { program_id: "P03" } },
    ],
    fallback: false,
  };
}
export async function getStaticProps({ params }) {
  const programData = await fetchProgramDetails(params.program_id); //Fetch API
  return {
    props: {
      programData: programData.data,
    },
  };
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The option of only using /programs/[program_id].js is not valid because Dynamic Routes (including Catch-all routes) do not have an undefined state. So try it as following:

/pages
|_/index.js
|_/programs.js
|_/programs
   |_/[program_id].js
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda