Route parameters let a single route definition handle many URLs that share a pattern, like /users/42 and /users/99. This lesson covers defining, reading, and reacting to route and query parameters.
What Are Route Parameters?
A route parameter is a dynamic segment in a path, marked with a colon (like :id in /users/:id), that captures part of the URL as a named value your component can read. Query parameters (after a ? in the URL) work similarly for optional, non-positional values.
Angular exposes both through the injected ActivatedRoute service, either as an Observable (reacting to changes without recreating the component) or as a one-time snapshot.
{ path: ':id', component: X } + withComponentInputBinding()
Reacting to Parameter Changes
If a user navigates from /users/1 to /users/2 while the same UserDetailComponent instance stays active (a common router optimization), a snapshot read taken once in ngOnInit will not update. Subscribing to paramMap as an Observable correctly reacts to every change.
Modern Angular can bind route (and query) parameters directly to a routed component's inputs automatically, removing the need to manually read ActivatedRoute for simple cases.
// app.config.ts
provideRouter(routes, withComponentInputBinding())
// user-detail.component.ts
export class UserDetailComponent {
@Input() id!: string; // automatically bound from the ':id' route parameter
}
withComponentInputBinding() must be enabled once in the router configuration for this to work anywhere in the app.
Working With Query Parameters
Query parameters are ideal for optional state like pagination, sorting, or filters, values that shouldn't be part of the route's structural path but should still be shareable/bookmarkable in the URL.
Reading route parameters only once via snapshot when the component can be reused across parameter changes.
Forgetting that route parameters are always strings, comparing them directly to numbers without conversion.
Using a route (path) parameter for optional, non-positional filters instead of a query parameter.
Not enabling withComponentInputBinding() before relying on automatic input binding for route parameters.
Key Takeaways
Route parameters capture dynamic path segments defined with a colon, like :id.
Query parameters capture optional key/value pairs from the URL's query string.
Subscribing to paramMap/queryParamMap reacts correctly to changes on a reused component instance.
withComponentInputBinding() can bind route/query parameters directly to component inputs, reducing boilerplate.
Pro Tip
Enable withComponentInputBinding() in provideRouter() early in a project; it removes a large amount of repetitive ActivatedRoute parameter-reading code across every routed component.
You now understand route and query parameters. Next, learn about Child Routes for building nested layouts and views.