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

209
Visualizações
NextJS: Dynamic URL get auto redirected to root url(home page)

In NextJS I've created a dynamic page to fetch and display blog content, with the following URL https://example.com/blog/[blogId]

But when I try to access the URL on production the user gets redirected to root URL(home page) instead of the blog content page.

Below is my folder structure

pages

|__ blog

   |___ [blogId].tsx

Can anyone tell me what's going wrong here? PS: Locally this is working fine.

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

0

If you want to use [blogId] as the variable part of your URL string, you have to make sure the data being served from your data source exactly matches.

getStaticPaths should generate an array of blogID in your case, something like this:

export async function getStaticPaths() {
  const pages = await getPathsForBlogs();
  return {
    paths: pages?.map(({ node }) => `/blog/${blogID}`) || [],
    fallback: false,
  }
}

In getStaticPages, you'd ingest that stack of paths and Next will generate a page at each blogID. In this example, we send the data payload back to the component on the custom param page, which you'd desconstruct in your /pages/blog.js component.

export async function getStaticProps({ params, preview = false, previewData }) {
  const pageData = await getSingleActionPage(params.blogID, previewData);

  return {
    props: {
      preview,
      page: pageData ?? null,
    },
    revalidate: 60,
  }
}
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