Nested Layout components
Answered
Smith's Longspur posted this in #help-forum
Smith's LongspurOP
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
@Smith's Longspur 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
@Smith's Longspur Thank you so much
happy to help
@B33fb0n3 happy to help
Smith's LongspurOP
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
Smith's LongspurOP
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
@Smith's Longspur the first one is my rootlayout
alright. The first thing you need to do:
- Create 2 root layouts
- Create 2 root layouts
Smith's LongspurOP
yes
@B33fb0n3 alright. The first thing you need to do:
- Create 2 root layouts
Smith's LongspurOP
what do i do next
@Smith's Longspur 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
Smith's LongspurOP
Alr
So can you tell me the directories on how it should look like
like app/layout.tsx
like app/layout.tsx
Smith's LongspurOP
@B33fb0n3
@Smith's Longspur 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 routesSmith's LongspurOP
so should it look like this
@Smith's Longspur so should it look like this
Double-striped Thick-knee
yeah, does it work?
@Double-striped Thick-knee yeah, does it work?
Smith's LongspurOP
Yes tysm