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

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

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