Next.js Discord

Discord Forum

layout for subroutes

Answered
Mike posted this in #help-forum
Open in Discord
Hello, i have a page with an home page and /dashboard routes.

What is the best practice to create an layout for the subroutes like /dashboard /dashboard/users and so one.

Ive already created the layout. How i can implement it only in the subroutes?
Answered by !=tgt
like this
.
└── src/
    └── app/
        ├── page.tsx
        ├── layout.tsx
        └── dashboard/
            ├── page.tsx
            └── (subroutes)/
                └── layout.tsx
                    └── users/
                        └── page.tsx
View full answer

13 Replies

in a folder
who's name is enclosed in parentheses (so that it's not part of the route)
and then put the layout in the root of that folder
like this
.
└── src/
    └── app/
        ├── page.tsx
        ├── layout.tsx
        └── dashboard/
            ├── page.tsx
            └── (subroutes)/
                └── layout.tsx
                    └── users/
                        └── page.tsx
Answer
Thank you very much 🙂
And where I need to define this layout? In dashboard/page.tsx?
Ahh, I only need to define it in the old version.
I understand
@Mike I understand
make sure to mark the answer with the bot :)
Yes 🙂 but one question. Why I can’t put it in the /dashboard folder? Because the default page should have the layout too?
yeah that's why
Okay.