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

74
Visualizações
How to handle different Headers in Reactjs

I am working with Reactjs(Nextjs) and i have different "Header" for home page and different header for rest of pages,So i want to know that how can i use different headers in nextjs,I created "Layout.js" and put "Header" and "footer" inside this and use/import this file in "_app.js", but how can we do this for different headers ? Here is my _app.js file

import React from 'react';
import App from 'next/app';
import Layout from '../components/layout'
import type { AppProps } from 'next/app'
function MyApp({ Component, pageProps }: AppProps) {
  return (
    <>
     <Layout>
     <Component {...pageProps} />
     </Layout>
    </>
   );
}
export default MyApp
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  1. Create a new layout for your homepage, say HomeLayout.
  2. Attach this HomeLayout as a property getLayout on your homepage component.
// src/pages/index.js
import HomeLayout from 'layout/HomeLayout';

const Home = () => {
    return (
        <h1>Home page </h1>
    );
};

Home.getLayout = HomeLayout;

export default Home;
  1. Use this newly attached property on _app.js to conditionally determine which layout to render. If there exists getLayout on a component, we use that layout else we will fallback to our default Layout.
// _app.js
import Layout from '../components/layout'

const App = ({ Component, pageProps }) => {
    const AppLayout = Component.getLayout || Layout;
    return (
      <AppLayout>
        <Component {...pageProps} />
      </AppLayout>
    );
};

export default App;

Reference:

  1. https://nextjs.org/docs/basic-features/layouts
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