Router animation
Comprehensive guide for creating smooth page transition animations with Aurelia's router
Create smooth, professional page transitions when navigating between routes using Aurelia's powerful lifecycle hooks. This guide covers various animation strategies from simple fades to complex directional transitions.
Why Router Animations?
Page transitions serve important UX purposes:
Continuity - Help users understand navigation context
Polish - Make your SPA feel more app-like and professional
Direction awareness - Show forward/backward navigation visually
Focus management - Guide user attention during transitions
Basic Concepts
Router animations leverage lifecycle hooks to coordinate animations during navigation. The key hooks for animations are:
loading- Called before a new route loads (detect navigation direction)attaching- Animate the incoming viewdetaching- Animate the outgoing viewcreated- Get references to the component's host element
Simple Fade Transition
The simplest router animation is a fade in/out effect:
Register the hooks in your route components:
Or globally in your app:
Direction-Aware Slide Animation
Create slide animations that respond to forward/backward navigation:
Using Anime.js for Router Transitions
For more advanced animations, integrate Anime.js:
Multiple Animation Styles
Create a reusable animation system with multiple styles:
Usage:
Per-Route Animation Configuration
Apply different animations to different routes:
Coordinated Page Transitions
Animate multiple elements during route transitions:
Accessibility Considerations
Always respect user preferences for reduced motion:
Performance Tips
1. Use GPU-Accelerated Properties
Always animate transform and opacity for best performance:
2. Clean Up Animations
Cancel animations if navigation is interrupted:
3. Add Will-Change for Complex Animations
Common Patterns
Vertical Slide
Scale and Fade
Rotation
Debugging Router Animations
Add logging to understand animation timing:
Summary
Router animations in Aurelia are powered by lifecycle hooks that give you full control over page transitions. Key takeaways:
Use
attachingfor enter animations anddetachingfor exit animationsAlways return promises from animation hooks
Use
loadingandunloadingto detect navigation directionPrefer
transformandopacityfor best performanceRespect
prefers-reduced-motionfor accessibilityCancel animations in
unbindingif navigation is interrupted
For more animation techniques and patterns, see the comprehensive Animation Guide.
Last updated
Was this helpful?