App configuration and startup

Configure Aurelia applications, register global resources, and choose the startup pattern that fits your project.

Application Startup

Aurelia provides two main approaches for application startup: a quick setup using static methods with sensible defaults, and a verbose setup that gives you complete control over configuration.

Before you start: If you have not already chosen a project scaffold, walk through the section overview for context on how this guide fits with enhancement, routing, and composition topics.

Quick startup

The quick startup approach uses static methods on the Aurelia class and is the most common choice for new applications.

import Aurelia from 'aurelia';
import { RouterConfiguration } from '@aurelia/router';

import { MyRootComponent } from './my-root-component';

// Simplest startup - hosts to <my-root-component> element, or <body> if not found
Aurelia.app(MyRootComponent).start();

// Register additional features before startup
Aurelia
  .register(
    RouterConfiguration.customize({ useUrlFragmentHash: false })
  )
  .app(MyRootComponent)
  .start();

// Specify a custom host element
Aurelia
  .register(
    RouterConfiguration.customize({ useUrlFragmentHash: false })
  )
  .app({
    component: MyRootComponent,
    host: document.querySelector('my-start-tag')
  })
  .start();

// Async startup pattern (recommended)
const app = Aurelia
  .register(
    RouterConfiguration.customize({ useUrlFragmentHash: false })
  )
  .app(MyRootComponent);

await app.start();

Verbose Startup

The verbose approach gives you complete control over the DI container and configuration. Use this when integrating Aurelia into existing applications or when you need fine-grained control.

When to use verbose startup:

  • Integrating Aurelia into existing applications

  • Custom DI container configuration needed

  • Multiple Aurelia apps in one page

  • Advanced debugging or testing scenarios

StandardConfiguration includes essential services like:

  • Template compiler and renderer

  • Binding engine and observers

  • Custom element/attribute support

  • Built-in value converters and binding behaviors

  • DOM event handling and delegation

  • Shadow DOM and CSS module support

Registering Global Resources

Registering a single custom element

To make a custom element globally available throughout your application, register it before calling app().

Registering multiple resources

Group related components into resource modules for better organization.

src/components/index.ts:

src/main.ts:

Registering other resource types

Advanced Configuration

Custom DI registrations

Environment-specific configuration

Enhancement Mode

Sometimes you need Aurelia to light up markup that already exists in the DOM. Instead of calling app(), reach for Aurelia.enhance:

Enhancement is ideal for progressive hydration, CMS integrations, or widgets embedded in non-Aurelia pages. You can register resources before enhancing, provide a custom DI container, and tear down the enhanced view by calling enhanceRoot.deactivate() when you’re done.

For a full guide, including cleanup patterns, lifecycle hooks, and advanced recipes, see the dedicated Enhance article.

Next steps

  • Continue with Enhance for progressive integration scenarios.

  • Wire services using dependency injection once your shell is running.

  • Explore choosing a router to add navigation after the app is bootstrapped.

Last updated

Was this helpful?