Nested Layout components
Answered
Sage Thrasher posted this in #help-forum
Sage ThrasherOP
Hi, i'm trying to implement my navbar and footer into my landing page and im also tryna make it appear in every page like in a layout.tsx but if i try put it in my root layout it displays the navbar and footer into my dashboard and i dont want that, what should i do. this is my website https://serverside.zephal.org, i only want the navbar and footer to appear in the / directory and not the /dashboard but also renders it in every page
Answered by B33fb0n3
you can create route groups that contains your specific layouts. In your case you also need multiple root layouts. So take a look at this: https://nextjs.org/docs/app/building-your-application/routing/route-groups#creating-multiple-root-layouts
32 Replies
@Sage Thrasher Hi, i'm trying to implement my navbar and footer into my landing page and im also tryna make it appear in every page like in a layout.tsx but if i try put it in my root layout it displays the navbar and footer into my dashboard and i dont want that, what should i do. this is my website https://serverside.zephal.org, i only want the navbar and footer to appear in the / directory and not the /dashboard but also renders it in every page
you can create route groups that contains your specific layouts. In your case you also need multiple root layouts. So take a look at this: https://nextjs.org/docs/app/building-your-application/routing/route-groups#creating-multiple-root-layouts
Answer
@Sage Thrasher Thank you so much
happy to help
@B33fb0n3 happy to help
Sage ThrasherOP
wait
so like
if i were to add
<Navbar/>
and <Footer/>
How will i do that
Do i put it in the root layout or
I want to specifically add the navbar and footer in the / directory
yea, you would create mutliple root layouts. And one root layout would contain the Navbar and the Footer and the other root layout wouldn't
Sage ThrasherOP
this is my dashboard folder
and this is my app folder
"use client";
import Sidebar from "./(components)/Sidebar";
import Navbar from "./(components)/Navbar";
import Particles from "@/components/magicui/particles";
import React, { useState } from "react";
import Kbar from "./(components)/ui/kbar";
import { motion } from "framer-motion";
export default function RootLayout({
children,
}: Readonly<{
children: React.ReactNode;
}>) {
const [color] = useState("#FFC0CB");
// Create a unique key based on a counter or a route identifier if using routing.
const uniqueKey = new Date().getTime(); // Or use a route-based identifier
return (
<div className="grid text-white min-h-screen bg-black-100 w-full lg:grid-cols-[280px_1fr]">
<Particles
className="absolute z-20 inset-0"
quantity={100}
ease={80}
color={color}
refresh
/>
<Sidebar />
<div className="flex-1">
<Navbar>
<main className="z-40 relative pb-5 flex flex-col gap-4 px-5 lg:gap-6">
<Kbar />
{children}
</main>
</Navbar>
</div>
</div>
);
}the first one is my rootlayout
and the second is my dashboard
@Sage Thrasher the first one is my rootlayout
alright. The first thing you need to do:
- Create 2 root layouts
- Create 2 root layouts
Sage ThrasherOP
yes
@B33fb0n3 alright. The first thing you need to do:
- Create 2 root layouts
Sage ThrasherOP
what do i do next
@Sage Thrasher what do i do next
then put in one root layout the Navbar and also the Footer
@B33fb0n3 then put in one root layout the Navbar and also the Footer
Sage ThrasherOP
Alr
So can you tell me the directories on how it should look like
like app/layout.tsx
like app/layout.tsx
Sage ThrasherOP
@B33fb0n3
@Sage Thrasher So can you tell me the directories on how it should look like
like app/layout.tsx
Double-striped Thick-knee
- App
- (home) // Main application routes
- layout.tsx // Contains Header and Footer for the main pages
// Add subfolders or files here to define root routes for home
- dashboard // Dashboard-specific routes
- layout.tsx // Layout without Header and Footer
// Add subfolders or files here to define dashboard routesSage ThrasherOP
so should it look like this
@Sage Thrasher so should it look like this
Double-striped Thick-knee
yeah, does it work?
@Double-striped Thick-knee yeah, does it work?
Sage ThrasherOP
Yes tysm