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

232
Visualizações
NextJS - Component.name have different value on BUILD

I have a pages that have different Layouts. Inorder to Switch Layout I am using the Component.name in _app.js. It is working in Development but after building the project and using the npm start. It seems the Component.name doesn't contain the correct value making the Layout Component used by other pages.


      if (Component.name === 'Login') {
        return <Component {...{ pageProps, toast }} />;
      }
      return (
        <Layout>
          <Component {...{ pageProps, toast }} />
        </Layout>
      );

Is there something that I have missed here? Or this is not the correct way to implement something like this.

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

0

I am facing the same issue. After some digging, it turns out it was because files were minified in production. We can set the component name explicitly before we export, then we should be able to access it in production.

// Login Component
function Login() {....}

Login.displayName = "Login"

export default Login;

then you can access it with

      if (Component.displayName === 'Login') {
        return <Component {...{ pageProps, toast }} />;
      }
      return (
        <Layout>
          <Component {...{ pageProps, toast }} />
        </Layout>
      );
about 4 years ago · Juan Pablo Isaza Relatório

0

You could use the pathname of the router here to check this:

  if (["/login"].includes(router.pathname)) {
    return <Component {...{ pageProps, toast }} />;
  }
  return (
    <Layout>
      <Component {...{ pageProps, toast }} />
    </Layout>
  );
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