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 referencestandardConfiguration(): Loaded default framework featuresglobalResources(): Made components available app-widefeature(): Loaded grouped functionalityplugin(): Added third-party packagessetRoot(): Defined the root component
What's improved in v2:
No more
PLATFORM.moduleName: Works with any bundler out of the boxFluent 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 syntaxAuto-CSS loading: CSS files with matching names are loaded automatically
resolve()function: Alternative to constructor injection for better composabilityNo
<template>wrapper: Optional in v2 for cleaner templatesModern 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 → define → 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:
disposehook 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 bloatBetter type safety: Full TypeScript support with interfaces
DI.createInterface(): Create typed injection tokens with defaultsFlexible 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/loadingvscanActivate/activate,canUnload/unloadingvscanDeactivate/deactivateType 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: Easy to set page titles based on loaded data
Data Binding
Data binding has been enhanced with better performance, new features, and more intuitive syntax.
Key improvements:
.classbinding: Clean conditional CSS classesAutomatic computation: No need for
@computedFromdecoratorLambda expressions: Filter and transform data in templates
Better ref binding:
component.reffor accessing component instancesFunction 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?