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

365
Views
Nested Layouts in Next.js

I want to create a nested layout in next.js. I have also a parent layout that contains Header and Footer components. I am using that Layout in the _app.js file.

_app.js file

import Layout from "../components/Layouts/Layout";
import "../styles/globals.css";

function MyApp({ Component, pageProps }) {
  return (
    <>
      <Layout>
        <Component {...pageProps} />
      </Layout>
    </>
  );
}

export default MyApp;

Sidebar.js

import Link from "next/link"
export default function Sidebar() {
    return (
        <div>
            <ul>
                <li><Link href="docs/page1"><a>Page 1</a></Link></li>
                <li><Link href="docs/page2"><a>Page 2</a></Link></li>
                <li><Link href="docs/page3"><a>Page 3</a></Link></li>
                <li><Link href="docs/page4"><a>Page 4</a></Link></li>
                <li><Link href="docs/page5"><a>Page 5</a></Link></li>
            </ul>
        </div>
    )
}

Now I have a docs page with a Sidebar component. Now I do not want to render the Sidebar component on every docs page. I want to create a nested layout that only renders in a particular route. In my case, the nested layout should be rendered in the /docs path. Now I have pages inside the pages/docs directory something like this => enter image description here

Now I want a nested layout that would be wrapped up of the parent Layout. The nested layout may contain a Sidebar component.

about 4 years ago · Juan Pablo Isaza
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!