What are Named Routes?
Named routes let you reference routes by name instead of hard-coding paths everywhere. This makes your code more maintainable and refactor-friendly while providing type-safe navigation.
Before (Hard-coded paths)
After (Named routes)
Registering Named Routes
Register your routes once in your main.js or a routes configuration file:
Register Multiple Routes
Register Single Route
Using Named Routes
The link action supports multiple convenient formats:
1. Legacy String Format (Still Works)
2. Object with Direct href
3. Named Route with Parameters
4. Array Shorthand (Recommended)
Named Routes with Query Parameters
Easily add query parameters to your named routes:
Object Format
Array Format
Direct href with Query
Advanced Options
The object format supports additional options:
Options Reference
route- Named route (mutually exclusive with href)href- Direct path (mutually exclusive with route)params- Route parameters objectquery- Query string parameters objectreplace- Use replaceState instead of pushState (default: false)disabled- Disable navigation (default: false)
Programmatic Navigation
push() and replace() now support the same convenient formats as the link action!
Utility Functions
hasRoute(name)
Check if a route is registered:
getRoutes()
Get all registered routes:
clearRoutes()
Clear all registered routes (useful for testing):
TypeScript Support
Full TypeScript support for type-safe navigation:
Practical Examples
Navigation Menu
User Profile Links
Dynamic List Navigation
Benefits
🔒 Type-safe
Define routes once, use them everywhere with TypeScript support
🔧 Refactor-friendly
Change URL patterns without updating every link in your codebase
✨ Cleaner code
No more string concatenation for building dynamic URLs
🎯 Flexible
Multiple syntax options - choose what fits your use case
🔄 Backward compatible
Old <a href="/path" use:link> still works!
📝 Self-documenting
Route names make code more readable and maintainable
Migration Guide
No breaking changes! Your existing code continues to work. You can gradually adopt named routes:
Try It Live
See named routes in action with our interactive demo: