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

227
Views
Creating a home page dynamically in NextJs

I'm trying to create all my pages using NextJs with the slugs/uri I get when fetching the data, however when trying to create the home page it says.

Error: The provided path `/` does not match the page: `/[slug]`.

[slug].tsx is located in the page folder. I removed the index.js since I would like to have the home page the same page layout as other pages.

Currently getting the static paths like this:

export async function getStaticPaths() {
  const allPages = await getAllPostsWithSlug();

  return {
    paths: allPages.edges.map(({ node }) => `${node.uri}`) || [],
    fallback: true,
  };
}

The error I got makes sense, but I couldn't really find a solution to create my home page in the same page template.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

As per the documentation, you can use an optional catch-all route.

Name your page file [[...slug]].js, and then use something like the this for the paths prop in getStaticPaths:

paths: [
  { params: { slug: [] } },
  { params: { slug: ['foo'] } },
  { params: { slug: ['bar'] } },
]

FWIW - if you want to share components from the main template (i.e. header, nav, footer etc), I recommend using a custom _app.js page. If your homepage really is identical to your other pages, it might be worth re-visiting the design!

Good luck!

about 4 years ago · Juan Pablo Isaza Report

0

Since [...slug] is not the same as [slug] as it grabs sub-paths as well, you can achieve a closer match using just [slug].js and adding a rewrite to your next.config.js like so:

  async rewrites() {
    return [
      {
        source: '/',
        destination: '/homepage',
      },
    ]
  },

Then you handle the homepage slug as your homepage, just like any other CMS page or post.

(/homepage can be anything you want, e.g. /index)

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!