Error handling
Learn how to handle navigation errors, implement error recovery patterns, and create robust routing experiences.
Types of Router Errors
Navigation Errors
import { IRouterEvents, NavigationErrorEvent } from '@aurelia/router';
import { resolve } from '@aurelia/kernel';
export class ErrorHandler {
private routerEvents = resolve(IRouterEvents);
attached() {
this.routerEvents.subscribe('au:router:navigation-error', (event: NavigationErrorEvent) => {
console.error('Navigation failed:', event.error);
console.log('Failed instructions:', event.instructions);
console.log('Navigation ID:', event.id);
this.handleNavigationError(event.error);
});
}
private handleNavigationError(error: unknown) {
if (error instanceof Error) {
// Handle specific error types
switch (error.name) {
case 'UnknownRouteError':
this.router.load('not-found');
break;
case 'NetworkError':
this.showRetryDialog();
break;
default:
this.showGenericError(error.message);
}
}
}
}Component Loading Errors
Hook Validation Errors
Error Recovery Configuration
Automatic Route Tree Restoration
Strict Error Handling
Error Handling Patterns
Global Error Boundary
Component-Level Error Handling
Fallback Routes and Components
Error Recovery Strategies
Retry with Exponential Backoff
Graceful Degradation
Error Monitoring and Logging
Comprehensive Error Tracking
Best Practices
1. Always Handle Navigation Errors
2. Provide User Feedback
3. Use Appropriate Error Recovery
Last updated
Was this helpful?