Skip to main content

Route Configuration

Route configuration defines the mapping between URL paths and components in your Angular application. Routes are defined using the Routes type and Route interface.

Import

Routes Type

An array of Route objects that defines the routing configuration for the application.

Route Interface

Route Properties

Path Configuration

path

The URL path to match. Supports:
  • Static paths: 'home', 'about'
  • Dynamic parameters: 'users/:id', 'posts/:postId/comments/:commentId'
  • Wildcard: '**' (matches any URL)
  • Empty path: '' (matches without consuming URL segments)
Examples:

pathMatch

The path matching strategy:
  • 'prefix' (default): Matches when the URL starts with the path
  • 'full': Matches only when the URL exactly matches the path
Example:
Always use pathMatch: 'full' when redirecting from an empty path, otherwise the redirect will apply to all URLs.

matcher

A custom function for URL matching. Cannot be used with path. Type Definition:
Example:

Component Configuration

component

The component to instantiate when the path matches. Example:

loadComponent

Lazy-load a standalone component. Examples:

redirectTo

URL to redirect to when this path matches. Can be:
  • Absolute path: '/home'
  • Relative path: '../other'
  • Path with parameters: '/users/:id'
  • Function for conditional redirects: RedirectFunction
Examples:

Child Routes

children

Nested child routes. Example:
Template for parent component:

loadChildren

Lazy-load child routes. Type Definition:
Examples:

Named Outlets

outlet

Name of the RouterOutlet where the component should be rendered. Example:
Template:
Navigate to named outlet:

Guards

canActivate

Guards that determine if the route can be activated. Example:

canActivateChild

Guards that determine if child routes can be activated. Example:

canDeactivate

Guards that determine if the route can be deactivated (e.g., unsaved changes). Example:

canMatch

Guards that determine if the route configuration can be matched. Example:

Data and Resolution

data

Static data associated with the route. Type:
Example:

resolve

Data resolvers that pre-fetch data before route activation. Type:
Example:

title

Page title for the route. Examples:

Additional Options

runGuardsAndResolvers

Defines when guards and resolvers should run. Type:
Example:

providers

Dependency injection providers for this route and its children. Example:

Common Route Patterns

Basic Routes

Parameterized Routes

Nested Routes

Lazy Loading

Protected Routes

Routes with Resolvers

See Also

Router Class

Router service API

Route Guards

Guard functions and interfaces

Routing Guide

Complete routing guide

Lazy Loading

Lazy loading feature modules