Best way to have multiple layouts?
Answered
Manx posted this in #help-forum
ManxOP
So basically i have my app which i've got a regular run of the mill homepage which is in the outermost app folder with the structure
>app
>>layout.tsx
>>page.tsx
Which is fine and works beautifully however the navbar on the home page that is within the layout.tsx file i don't want to be within the user dashboard
i have the structure
>app
>> dashboard (folder)
>>>layout.tsx
>>>page.tsx
>>layout.tsx
>>page.tsx
Currently i've opted for simply having in the outtermost layout.tsx file usePathname(); and i'm checking whether the pathname has '/dashboard/' or not before loading in the layout but this seems kind of hacky... is there any way around this at all, if not no worries.
>app
>>layout.tsx
>>page.tsx
Which is fine and works beautifully however the navbar on the home page that is within the layout.tsx file i don't want to be within the user dashboard
i have the structure
>app
>> dashboard (folder)
>>>layout.tsx
>>>page.tsx
>>layout.tsx
>>page.tsx
Currently i've opted for simply having in the outtermost layout.tsx file usePathname(); and i'm checking whether the pathname has '/dashboard/' or not before loading in the layout but this seems kind of hacky... is there any way around this at all, if not no worries.
Answered by Spectacled bear
Create a folder with a name (navbar)
Create a layout.tsx file, do the code for the navbar
place all the pages inside this folder where you want to show navbar
similar to other layouts. Group them using parenthesis eg (loggedin)
Create a layout.tsx file, do the code for the navbar
place all the pages inside this folder where you want to show navbar
similar to other layouts. Group them using parenthesis eg (loggedin)
4 Replies
Spectacled bear
Create a folder with a name (navbar)
Create a layout.tsx file, do the code for the navbar
place all the pages inside this folder where you want to show navbar
similar to other layouts. Group them using parenthesis eg (loggedin)
Create a layout.tsx file, do the code for the navbar
place all the pages inside this folder where you want to show navbar
similar to other layouts. Group them using parenthesis eg (loggedin)
Answer
@Spectacled bear Create a folder with a name (navbar)
Create a layout.tsx file, do the code for the navbar
place all the pages inside this folder where you want to show navbar
similar to other layouts. Group them using parenthesis eg (loggedin)
ManxOP
Ah i didn't think of it like that
So you'd have (homepage) >> All homepage pages and layout and then just leave the outtermost RootLayout pretty much empty?
So you'd have (homepage) >> All homepage pages and layout and then just leave the outtermost RootLayout pretty much empty?
@Manx Ah i didn't think of it like that
So you'd have (homepage) >> All homepage pages and layout and then just leave the outtermost RootLayout pretty much empty?
Spectacled bear
Didn't get you, but when you have a layout and it is wrapped inside a folder with ( ), its only applicable to its sibling not to the outside world.
@Spectacled bear Didn't get you, but when you have a layout and it is wrapped inside a folder with ( ), its only applicable to its sibling not to the outside world.
ManxOP
Yeah that's essentially what i asked, ah cool thanks 🙂