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

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

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