URL matrix notation places optional route parameters inside a path segment as semicolon-separated name-value pairs. These values can guide a component without being essential to route activation. The convention is outside the URL specification, although browsers support it. section 24.3.2
Use matrix parameters when a route can continue without the supplied values:
- Generate parameters as literal properties, such as name, category, and price. section 24.3.2
- Read them like required route parameters and let the component check whether each value exists. section 24.3.2
- Use present values to override repository data while retaining fallback values when parameters are absent. section 24.3.2
Editing a product with optional values
A generated route such as /form/edit/2;name=Lifejacket;price=48.95 can populate the edit form without relying entirely on a repository request. A fuller example adds category=Soccer, producing /form/edit/5;name=Stadium;category=Soccer;price=79500. section 24.3.2
Listing 24.16. An optional route parameter in the table.component.html file in the src/app/core folder
...
<button class="btn btn-warning btn-sm"
(click)="editProduct(item.id)"
[routerLink]="['/form', 'edit', item.id,
{name: item.name, category: item.category,
price: item.price}]">
Edit
</button>
...
See the Angular routerLink listing that constructs matrix parameters from product properties. section 24.3.2
