Route Configuration
Route configuration defines the mapping between URL paths and components in your Angular application. Routes are defined using theRoutes type and Route interface.
Import
Routes Type
Route objects that defines the routing configuration for the application.
Route Interface
Route Properties
Path Configuration
path
- Static paths:
'home','about' - Dynamic parameters:
'users/:id','posts/:postId/comments/:commentId' - Wildcard:
'**'(matches any URL) - Empty path:
''(matches without consuming URL segments)
pathMatch
'prefix'(default): Matches when the URL starts with the path'full': Matches only when the URL exactly matches the path
matcher
path.
Type Definition:
Component Configuration
component
loadComponent
redirectTo
- Absolute path:
'/home' - Relative path:
'../other' - Path with parameters:
'/users/:id' - Function for conditional redirects:
RedirectFunction
Child Routes
children
loadChildren
Named Outlets
outlet
Guards
canActivate
canActivateChild
canDeactivate
canMatch
Data and Resolution
data
resolve
title
Additional Options
runGuardsAndResolvers
providers
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
