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

244
Visualizações
Next.js overlaps static route with dynamic route

I am using Next.JS application routing system.

I have created a dynamic route with structure like pages/[country]/[language]/index.js.

Also there is a static route with structure pages/cz/cz/index.js.

Issue appears then i am on static page and trying to navigate throught Link component to access static route content in my case should go to home page & reload same page, instead of that dynamic route content is rendered.

In my case link is just simple navigation to home page <Link to="/"> for both routes. But maybe issue lies on how index.js file is setup for predefined & dynamic routes.

cz/cz/index.js

export { default } from '../../../components/HomePage/';

const { getStaticProps } = createRoute({
  path: '/',
  locale: 'cs',
});

export { getStaticProps };

[country]/[language]/index.js

export { default } from '../../../components/HomePage/v2';

const { getStaticPaths, getStaticProps } = createRoute({
  path: '/',
  exclude: ['cs'],
  otherLocales: ['cs'],
});

export { getStaticPaths, getStaticProps };

createRoute

export default function createRoute({
  path,
  otherLocales,
  getPathParams,
  locale,
} = {}) {
  const locales = _.without(include, ...exclude);
  return {
    getStaticPaths: createGetStaticPaths({
      locales,
      getPathParams,
    }),
    getStaticProps: createGetStaticProps({
      path,
      locale,
      locales,
      otherLocales,
    }),
  };
}

Pages structure

enter image description here

So why [country]/[language]/index.js overrides cz/cz/index.js ?

So is there anything available in nextJS route to match a URL absolutely?

Or insure that going from static route should go to static route?

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

0

Following next.js documentation predefined routes take precedence over dynamic routes, and dynamic routes over catch all routes. Take a look at the following examples:

  • pages/post/create.js - Will match /post/create
  • pages/post/[pid].js - Will match /post/1, /post/abc, etc. But not /post/create
  • pages/post/[...slug].js - Will match /post/1/2, /post/a/b/c, etc. But not /post/create, /post/abc

In your case you have defined predefined routes cz/cz/index.js and this route have priority

about 4 years ago · Juan Pablo Isaza Relatório

0

If you happen to be using redirects, note that they are processed before next ever goes to the pages.

Redirects are checked before the filesystem which includes pages and /public files.

https://nextjs.org/docs/api-reference/next.config.js/redirects

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