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.

Note: While this guide uses router-direct examples, the animation techniques work with both router-direct and @aurelia/router. The @aurelia/router package is now the recommended router for new projects.

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 view

  • detaching - Animate the outgoing view

  • created - 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 attaching for enter animations and detaching for exit animations

  • Always return promises from animation hooks

  • Use loading and unloading to detect navigation direction

  • Prefer transform and opacity for best performance

  • Respect prefers-reduced-motion for accessibility

  • Cancel animations in unbinding if navigation is interrupted

For more animation techniques and patterns, see the comprehensive Animation Guide.

Last updated

Was this helpful?