DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsClean PCRecommendedOne scan can reveal what keeps slowing WindowsLook for cleanup and repair opportunities.Run Scan×
Skip to content
World desk4 min

Lazy-Loaded Routes in Angular: Choosing, Configuring, and Preloading

Angular lazy routes defer components or route subtrees into separately requested code. Learn how to choose a loader, configure preloading, and weigh the navigation tradeoffs.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use loadComponent to lazy-load a standalone routed component, or loadChildren to defer a route subtree. Angular’s router then requests the relevant code when needed, rather than including it in the initial route bundle. That can reduce initial JavaScript transfer, but it does not guarantee a faster app: a first visit to a lazy route may wait for another request. Angular generally recommends keeping primary landing pages eager and considering lazy loading for other pages.

How Angular lazy-loaded routes work

A route can refer to code directly or provide a loader function. With a lazy route, the loader commonly uses JavaScript’s dynamic import(). The build can place that code in a separate chunk, which the router requests when the route is visited. Lazy loading changes when code is transferred; it does not remove that code or promise a particular performance gain.

As an Amazon Associate I earn from qualifying purchases.

The tradeoff is between initial work and later navigation: less route code may be needed at startup, while a first visit to a deferred route may require a network request. Angular cautions that future requests can be undesirable, especially when an application has multiple nested lazy-loading levels. See Angular’s lazy-loaded routes performance guidance.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Choose between loadComponent and loadChildren

Route property Use it for Typical loader
loadComponent A standalone routed component () => import('./reports/reports-page')
loadChildren A child route configuration or a lazy NgModule () => import('./admin/admin.routes')

Use loadComponent when the destination is one standalone component. Use loadChildren when the route opens a subtree whose child routes should be loaded together, or when loading a lazy NgModule. Angular’s Route API and LoadChildrenCallback API describe the supported route loader types.

Configure a lazy standalone component

In a route file that imports Routes, define the path and return the component from a dynamic import:

import { Routes } from '@angular/router';

export const routes: Routes = [
  {
    path: 'reports',
    loadComponent: () => import('./reports/reports-page'),
  },
];

This direct form works when the imported module’s default export is the component. If it uses a named export, select that export from the import promise:

loadComponent: () =>
  import('./reports/reports-page').then(m => m.ReportsPage)

For a route subtree, point loadChildren at a file exporting a route array. A lazy NgModule is also supported:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
{
  path: 'admin',
  loadChildren: () => import('./admin/admin.routes'),
}

The Angular v20 route-definition guide shows lazy standalone components and nested-route configuration.

Decide which routes should be lazy

Do not add a lazy boundary to every route by default. Angular’s general guidance is to keep primary landing pages eager and consider lazy loading other pages. Apply that guidance to actual route roles and usage: code required by the first view may be worth having ready, while a less central or conditionally visited feature may be a better candidate for deferral.

  • Initial transfer and parsing: eager route code is available with the initial application code; lazy route code is placed in chunks requested later.
  • First visit: an eager destination is already available, while a lazy destination may wait for its chunk unless it has been preloaded or cached.
  • Background resource use: preloading can move requests earlier, but consumes bandwidth and memory.
  • Nested boundaries: multiple levels can add requests. Measure navigation in your application instead of assuming that more splits are faster.

The reviewed Angular guidance gives qualitative tradeoffs, not a universal route-count threshold, expected bundle reduction, or load-time percentage. Compare the initial chunks, likely visit patterns, and first-navigation timing in your own application.

Choose when lazy routes preload

Preloading is a separate router policy: it determines whether lazy code is fetched before a user first visits that route. Angular documents these built-in choices:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Strategy Behavior Tradeoff
NoPreloading The default; lazy modules load when a user navigates to them. Does not spend bandwidth on a route before it is requested, but its first visit may wait for the chunk.
PreloadAllModules Begins loading lazy modules after initial navigation. Can make later visits ready sooner, while background downloads use bandwidth and memory.
Custom PreloadingStrategy Loads routes selected by application logic, such as routes marked with data: { preload: true }. Can focus background work on selected routes; the application must define the selection behavior.

Start with the default unless observed first visits show a reason to change it. If selected routes are both likely to be visited and costly to fetch at the moment of navigation, a selective strategy can preload them. Background requests may compete with images, API calls, or other critical resources, so consider that cost as well. Angular documents built-in and custom strategies in Customizing route behavior.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Use dependencies inside a route loader

Angular runs route loader functions in the route’s injection context. A loader can call inject() for dependencies available on that route, inherited from a parent route, or provided globally. This supports context-aware choices, such as selecting between components based on an injected feature-flag service. It is an advanced option; a direct dynamic import is the ordinary pattern when the route always loads the same component.

Migrate eligible eager routes with the Angular CLI

Angular provides a schematic that converts eligible eagerly loaded standalone route components to loadComponent imports:

ng generate @angular/core:route-lazy-loading

To limit the migration to a part of the application, pass a path:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
ng generate @angular/core:route-lazy-loading --path src/app/feature

The schematic searches common route declarations, including RouterModule.forRoot, RouterModule.forChild, Router.resetConfig, provideRouter, and variables typed as Routes or Route[]. It only converts eligible standalone route components. For a route component declared in an NgModule, Angular’s route lazy-loading migration guide advises considering a move to standalone before running the migration again. Review the generated changes and test routing behavior through your normal project workflow; code transformation alone does not establish a performance improvement.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
PC Slower Than It Used to Be?Free scan - under a minute

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.