Overview
Routes in the Medusa admin dashboard are powered by React Router 6. You can create custom routes to:- Add new pages for custom functionality
- Create nested routes under existing sections
- Add items to the sidebar navigation
- Build multi-page workflows
Creating a Custom Route
Basic Route
Create a new route by defining a React component and exporting a route configuration:
The route will be automatically registered and accessible at
/analytics.
Route Configuration Options
ThedefineRouteConfig function accepts the following options:
Route File Structure
The file path determines the route path:Dynamic Routes
Use[param] syntax for dynamic route segments:
Nested Routes
Nest your custom routes under existing dashboard sections:packages/admin/admin-shared/src/extensions/routes/constants.ts:1):
/orders/products/inventory/customers/promotions/price-lists
Data Loading
Use React Router loaders for data fetching:Using the Admin SDK
Fetch data using the Medusa Admin SDK:Navigation
Programmatic Navigation
Use React Router hooks for navigation:Links
Layouts
Custom Layout
Create a layout for multiple related routes:Settings Routes
Add custom settings pages:Route Guards
Protect routes with authentication or permissions:Complete Example
Here’s a complete example with data fetching, forms, and navigation:Best Practices
Use Meaningful Route Paths
Use Meaningful Route Paths
Choose route paths that clearly describe the page content (e.g.,
/reports/sales instead of /r/s).Implement Loading States
Implement Loading States
Always show loading indicators while fetching data to improve user experience.
Handle Errors Gracefully
Handle Errors Gracefully
Use error boundaries and show helpful error messages when data loading fails.
Leverage TanStack Query
Leverage TanStack Query
Use TanStack Query for data fetching to get automatic caching, refetching, and optimistic updates.
Next Steps
- Learn about custom widgets
- Explore dashboard customization
- Review the JavaScript SDK for API integration