Next.js Discord

Discord Forum

remove header for a certain page but layout.js not working

Answered
CHEEMDA MAN posted this in #help-forum
Open in Discord
Avatar
i was trying to remove my header from a certain page by making different layout.js for that route and it removed successfully but when i'm refreshing the page the header appear on that page i'm attaching my app folder image so you'll know how i set my layout.js
Image
Answered by James4u (Tag me if needed)
so as I said, app/layout.js is sort of global layout that covers all of your pages
View full answer

80 Replies

Avatar
show me your app/layout.js and app/signin/layout.js
I believe you have something wrong on your codebase.
so let say you have two types of pages with different header
https://nextjs.org/docs/app/building-your-application/routing/route-groups
group them using route group and have your layout.jsx for them
@CHEEMDA MAN let me know the result
Avatar
hey
here is my signin/layout.js
Image
and here is my /layout.js
Image
@James4u (Tag me if needed)
Avatar
well, you have messed up everything
Avatar
howw
Avatar
as Isee html and body tags in your app/signin/layout.js
Avatar
here it is
Avatar
so app/layout.js is the root layout that covers all of your pages
Avatar
yea
Avatar
yeah, you shouldn't have them in your sub layout
Avatar
i have to remove html and body tags from it?
Avatar
so the output is like
<RootLayout>
<SubLayout>
</SubLayout>
</RootLayout>
yeah
just take a min to read about route groups
Avatar
done
ah that was i try i suppose to write done
Avatar
okay but you should notice you still get header in your signin page
Avatar
Image
Avatar
it's because as I said /app/layout.js is sort of root layout that covers the whole pages
you also don't need to import global.css there
Avatar
oh okay so i have to remove header from that and add a sub layout in my admin folder
oh ok ok
Avatar
yeah, that should also work
but think in this way, you have lots of routes to add header
right? then you have to create sub layout with header
like you are duplicating the same code
Avatar
yeah im thinking thee same thing
Avatar
route groups are there to solve that issue
Avatar
oh okay
Avatar
Border Terrier
i was just about to link it
Avatar
group the routes (that need headers) (that doesn't need headers)
and create layout for those two route groups
that should solve the problem, right?
Avatar
okay
Avatar
Border Terrier
that will solve everything
Avatar
so i have to create (admin) (signin)
Avatar
I would suggest (auth) (public)
but yeah it's up to you
Avatar
ah okay is the name of group will appear in route?
Avatar
nope
Avatar
then ig your suggestion is better
Avatar
please mark solution to close the thread! 🙂
Avatar
is i'm using the correct way? @James4u (Tag me if needed)
Image
Avatar
Border Terrier
yes
Avatar
ah.. let me try it..
okay
Avatar
Border Terrier
but, wait
Avatar
well, I meant something different
Avatar
Border Terrier
just quick question
Avatar
by public, I meant all public pages that doesn't require authentication like landing pages (in the landing pages, blogs, they share the same header/navbar)
Avatar
..oh
askk
Avatar
and by auth, I meant pages that require authentication - after login, we normally have different layout
Avatar
ah actually this project will not contains any page without authentication exclude signin
Avatar
but as I said, you can define your route groups as you want - I think you know what you need to do
okay I see - in my scenario, login page is also public as everyone can access
Avatar
yeah..
ohhh thanks got your point
i have to shift my signin in public and dashboard in auth
greatt
@James4u (Tag me if needed) one last question is my app/(public)/layout.js have to look like this??
Image
Avatar
do you still have app/layout.js ? assuming yes
Avatar
yea..
Avatar
so as I said, app/layout.js is sort of global layout that covers all of your pages
Answer
Avatar
think, you already imported fonts, and css from global.css
Avatar
oh okay that means i dont need that
in my app/layout.js yeahh
Avatar
Nope, it doesn't mean you don't need it
so let say, you have those fonts and some client providers that are needed in both (public) and (auth)
Avatar
ah i mean i dont need html and body tags in sub layout
Avatar
your root layout is the place where you should import/wrap common things
Avatar
yeaa
Avatar
yeah, you don't need - You shouldn't have them
Avatar
ok ok thanks brother