The flat-routes convention allows you to define Remix/React Router routes using a flat file or folder structure instead of deeply nested directories. This makes the route tree easier to visualize by looking at the routes/ directory and simplifies refactoring.
Flat Files Convention
In this mode, routes are defined by filenames using dot notation. Dots represent URL segments or nesting levels.
about.tsx -> /about (Layout route)about.contact.tsx -> /about/contact (Child of about.tsx)about.index.tsx -> /about (Index route of about.tsx)_auth.login.tsx -> /login (Pathless layout _auth.tsx provides context but doesn't add a segment to the URL)users.$userId.tsx -> /users/:userId (URL parameter)docs.$.tsx -> /docs/* (Splat route)
Flat Folders Convention
In this mode, each route is a folder named after the route, and the actual route component is placed in an index.tsx file within that folder. This allows you to colocate components, styles, and server code with the route.
Example structure:
routes/
app.projects/
index.tsx <-- Layout file (app.projects.tsx)
project-card.tsx
app.projects.$id/
index.tsx <-- Route file (app.projects.$id.tsx)
To avoid losing the route file in a list of colocated files, you can use these aliases for index.tsx:
_index.tsx_layout.tsx_route.tsx
routes/
_auth.forgot-password.tsx
_auth.login.tsx
_auth.tsx
app.calendar.$day.tsx
app.calendar.index.tsx
app.calendar.tsx
app.tsx
app_.projects.$id.roadmap.tsx
app_.projects.$id.roadmap[.pdf].tsx