Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

75
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!