Skip to content

Seeking Advice on Implementing Nested Routes with Specific Layouts in Remix #9025

Closed Answered by sergiodxa
GOWxx asked this question in Q&A
Discussion options

You must be logged in to vote

As the error said, an index route can't have child routes, this is because index is always a leaf route (the last one, in this case /).

What you need is to create a pathless layout route that can have your shared layout.

app/routes/_layout.tsx <- here place your layout and <Outlet />
app/routes/_layout._index.tsx <- nested inside the layout, handles /
app/routes/_layout.contact.tsx <- nested inside the layout, handles /contact

I also like to name my global layout as _.tsx so the folder structure would look like this:

app/routes/_.tsx <- here place your layout and <Outlet />
app/routes/_._index.tsx <- nested inside the layout, handles /
app/routes/_.contact.tsx <- nested inside the layout…

Replies: 3 comments 6 replies

Comment options

You must be logged in to vote
1 reply
@GOWxx
Comment options

Comment options

You must be logged in to vote
5 replies
@GOWxx
Comment options

@dani-sanomads
Comment options

@somias
Comment options

@PatrickLeahey
Comment options

@hanford
Comment options

Answer selected by GOWxx
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
8 participants