For the complete documentation index, see llms.txt. This page is also available as Markdown.

Side-by-side comparison

Welcome to the comprehensive guide for migrating from Aurelia 1 to Aurelia 2! This guide will walk you through every aspect of the migration process, highlighting what's changed, what's improved, and what you need to know to successfully upgrade your application.

Aurelia 2 represents a significant evolution of the framework, bringing modern JavaScript features, improved performance, better tooling support, and a more streamlined developer experience. While many core concepts remain familiar, there are important changes that will make your applications more maintainable and powerful.


Table of Contents


Application Bootstrapping

The HTML Entry Point

The way you initialize your Aurelia application has been simplified and modernized.

The aurelia-app attribute told the framework where to find your main configuration file, and you had to include the aurelia-bootstrapper script.

Much cleaner! You simply place your root component's element in the HTML. No special attributes or bootstrap scripts needed. Your bundler configuration determines which JavaScript file serves as the entry point.

Application Configuration and Startup

The main configuration file has been significantly streamlined, with a more intuitive API and better bundler compatibility.

Key concepts in v1:

  • PLATFORM.moduleName: Required for Webpack compatibility - you had to wrap every module reference

  • standardConfiguration(): Loaded default framework features

  • globalResources(): Made components available app-wide

  • feature(): Loaded grouped functionality

  • plugin(): Added third-party packages

  • setRoot(): Defined the root component

What's improved in v2:

  • No more PLATFORM.moduleName: Works with any bundler out of the box

  • Fluent API: Chain registration and startup calls naturally

  • Type safety: Full TypeScript support with IntelliSense

  • Flexible registration: Multiple ways to register components and features

  • Better async support: Native Promise support throughout

Registering Global Resources

Making components available throughout your app is now more flexible and type-safe.


Components and Templates

Component Structure

Components in Aurelia 2 maintain the same view-model pairing but with enhanced conventions and flexibility.

Key improvements:

  • <import> vs <require>: More intuitive import syntax

  • Auto-CSS loading: CSS files with matching names are loaded automatically

  • resolve() function: Alternative to constructor injection for better composability

  • No <template> wrapper: Optional in v2 for cleaner templates

  • Modern CSS support: Full compatibility with modern CSS features

Template Syntax Enhancements

Aurelia 2 maintains familiar binding syntax while adding powerful new features.

New features in v2:

  • Lambda expressions: Filter and transform data directly in templates


Component Lifecycle

The component lifecycle has been expanded and refined with more hooks and better async support.

V1 Lifecycle Order: constructor โ†’ created โ†’ bind โ†’ attached โ†’ detached โ†’ unbind

V2 Lifecycle Order: constructor โ†’ hydrating โ†’ hydrated โ†’ created โ†’ binding โ†’ bound โ†’ attaching โ†’ attached โ†’ detaching โ†’ unbinding โ†’ dispose

Key improvements:

  • More granular control: Additional hooks for different stages

  • Better async support: Return Promises to control timing

  • Enhanced parameters: Controllers provide more context

  • Proper cleanup: dispose hook for final cleanup


Dependency Injection

Aurelia 2's DI system has been significantly enhanced with better type safety and more flexible registration options.

Key improvements:

  • resolve() function: Clean property injection without constructor bloat

  • Better type safety: Full TypeScript support with interfaces

  • DI.createInterface(): Create typed injection tokens with defaults

  • Flexible registration: Multiple patterns for different needs

  • Enhanced resolvers: More powerful dependency resolution strategies


Logging System

The logging system has been completely redesigned with a more powerful and flexible architecture.

Key improvements:

  • Sink-based architecture: More flexible than appenders

  • Better type safety: Full TypeScript support

  • Dependency injection: Seamless integration with DI system

  • Scoped loggers: Easy categorization and filtering

  • Multiple outputs: Send logs to different destinations simultaneously


Router and Navigation

The router has been redesigned with a focus on type safety, better performance, and modern navigation patterns.

Key improvements:

  • Declarative routing: Routes defined with decorators and configuration objects

  • Better lifecycle hooks: canLoad/loading vs canActivate/activate, canUnload/unloading vs canDeactivate/deactivate

  • Type safety: Full TypeScript support throughout

  • Lazy loading: Built-in support for code splitting

  • Enhanced parameters: Better access to route context and navigation state

  • Dynamic titles: Set route node title parts based on loaded data


Data Binding

Data binding has been enhanced with better performance, new features, and more intuitive syntax.

Key improvements:

  • .class binding: Clean conditional CSS classes

  • Automatic computation: No need for @computedFrom decorator

  • Lambda expressions: Filter and transform data in templates

  • Better ref binding: component.ref for accessing component instances

  • Function return in events: Event handlers can return functions


What's New in Aurelia 2

Beyond the improvements to existing features, Aurelia 2 introduces several entirely new capabilities:

Shadow DOM Support

Custom Attribute Patterns

Create your own binding syntax!

Enhanced Custom Elements

Watch Decorator for Advanced Observation


Migration Checklist

Use this checklist to ensure you've covered all aspects of your migration:

๐Ÿ—๏ธ Project Setup

๐Ÿงฉ Components

๐Ÿ”— Data Binding

๐Ÿšฆ Routing

๐Ÿ’‰ Dependency Injection

๐Ÿ“ Logging

๐ŸŽจ Templates and Features

๐Ÿงช Testing

๐Ÿ”ง Advanced Features


Conclusion

Migrating from Aurelia 1 to Aurelia 2 brings significant benefits: better performance, improved developer experience, enhanced type safety, and modern JavaScript features. While there are changes to learn, the core concepts remain familiar, and the improvements make building applications more enjoyable and maintainable.

The enhanced DI system, redesigned router, automatic observation, and new template features make Aurelia 2 a powerful platform for building modern web applications. Take your time with the migration, test thoroughly, and don't hesitate to leverage the new features that make development more productive.

Remember that Aurelia 2 maintains the same philosophy of convention over configuration and stays out of your way, while providing powerful tools when you need them. The migration effort will be rewarded with a more maintainable, performant, and developer-friendly application.

Last updated

Was this helpful?