Index Routes
Index routes render in their parent’s<Outlet /> when the parent’s path exactly matches the URL. They provide default content for layout routes and are commonly used for home pages, dashboards, and list views.
Basic Index Routes
Use theindex() helper to define an index route:
home.tsx at the root path /.
Index Routes in Nested Layouts
Index routes are most useful as default children of parent routes:/dashboard→ rendersdashboard.tsxwithoverview.tsxin the outlet (index route)/dashboard/analytics→ rendersdashboard.tsxwithanalytics.tsxin the outlet/dashboard/settings→ rendersdashboard.tsxwithsettings.tsxin the outlet
Parent Route with Index
File-Based Index Routes
When usingflatRoutes(), use _index for index routes:
Index vs. Layout Routes
Understand the difference between index routes and layout routes: Layout route (no path, wraps children):Loading Data in Index Routes
Index routes can have loaders like any other route:Index Route Actions
Handle form submissions in index routes:Navigation to Index Routes
Link to index routes using the parent’s path:Active Link Styling
Index routes require special handling for active link styling:end, the link to . (index) would always be active since all child paths start with /dashboard.
Multiple Index Routes (Layouts)
Different layout routes can have their own index routes:Index Route Redirects
Redirect from an index route:Error Boundaries
Index routes can have their own error boundaries:Index Route Meta
Export meta data for SEO:Common Patterns
Dashboard with Overview
Product Listing
Documentation Site
Best Practices
- Default content: Use index routes for the most common/default child view
- Use
endprop: Addendto NavLinks pointing to index routes - Descriptive names: Name index route files after their content (e.g.,
overview.tsxnotindex.tsx) - Avoid empty outlets: Always provide an index route for layouts with children
- Consider redirects: Redirect from index routes when user state requires it
- Data loading: Don’t hesitate to add loaders to index routes