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

228
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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