Next.js Discord

Discord Forum

Hide Navbar in certain pages.

Answered
shadow posted this in #help-forum
Open in Discord
Avatar
Hey devs, i have in the layout of the root directory an navbar, so every page have thta navbar, until then everyting is good, but in /home i want to replace the navbar with sidebar, for that i create an layout.tsx for the /home directory and put the sidebar there, but now the navbar and the sidebar appear, how can i when im at /home, hide the navbar and just show the sidebar?
Answered by Noronha
Something like that.
Image
View full answer

9 Replies

Avatar
and hide the navbar with css
Or... you can change the structure of your project in such a way that you'll put the navbar element on a layout.tsx for only pages that needs it.
Avatar
but i cant use thta function in the layout because is server component
Avatar
You can make it a client component if you like, but no problem.
In this case I would go with plan be:
Avatar
Something like that.
Image
Answer
Avatar
a layout for all the pages with navbar
and the home page without any layouts 🙂