Overview
While most applications use the standardRoute and RootRoute classes, you can create custom route types for:
- Domain-specific route requirements
- Specialized validation or authorization logic
- Custom route option types
- Integration with other libraries or frameworks
- Type-safe API route definitions
Route Class Anatomy
Understanding the route class structure is essential for customization:Creating Route Factories
Route factories help create routes with shared configuration:Basic Route Factory
Route Factory with Validation
Extending the Route Class
Create custom route classes by extending the baseRoute class:
Custom Route Options
Extend route options for domain-specific needs:Custom Root Routes
Create specialized root routes for different application sections:Type-Safe API Routes
Create fully typed API route definitions:Route Hooks Customization
Create custom hooks for your route types:Route Middleware Pattern
Implement a middleware pattern for routes:Framework-Specific Route Types
Create routes optimized for specific frameworks:Route Composition
Compose routes from smaller pieces:Validating Custom Routes
Ensure your custom routes maintain type safety:Best Practices
- Extend, don’t replace - Build on top of base Route class
- Maintain type safety - Ensure custom routes preserve TypeScript types
- Document custom behavior - Clearly document what your custom routes do
- Test thoroughly - Custom routes need comprehensive testing
- Keep it simple - Only customize when standard routes are insufficient
- Use factories - Prefer factory functions over class extension when possible
- Composition over inheritance - Use composition patterns for flexibility