Passing Optional Parameters to a Route
Query parameters allow you to pass optional parameters to a route such as pagination information.
For example, on a route with a paginated list, the URL might look like the following to indicate that we've loaded the second page:
localhost:3000/product-list?page=2
The key difference between query parameters and route parameters is that route parameters are essential to determining route, whereas query parameters are optional.
Passing Query Parameters
Use the [queryParams]
directive along with [routerLink]
to pass query parameters. For example:
Alternatively, we can navigate programmatically using the Router
service:
Reading Query Parameters
Similar to reading route parameters, the Router
service returns an Observable we can subscribe to to read the query parameters:
Last updated