liveBook · Manning

Optional segment

As explained in Pro Angular 16

An optional route parameter is a route value that may be included in a URL to provide additional information without being required for the route to function.

An optional route parameter adds URL information without making that information necessary for the route to function. Angular expresses these values with URL matrix notation: semicolon-separated name–value pairs attached to a route segment. section 24.3.2

Use optional segments when a component can improve its behavior with extra values but must still work without them:

  • Use supplied values to avoid a data-model request, then retain existing values when optional inputs are absent. section 24.3.2

Editing a product with optional values

A link can produce /form/edit/2;name=Lifejacket;price=48.95. The form reads name, category, and price, replacing the loaded product fields only when corresponding optional values are provided; price is parsed as a number.

How Pro Angular 16 covers it

How deep it goes
Explains matrix notation, link generation, component inputs, fallbacks, and parsing, but defers route activation until data availability.
Examples
Uses product-edit URLs carrying name, category, and price values as concrete examples.
What it assumes
Assumes route configuration and component input handling, while teaching optional-value presence checks and fallback behavior.
What you can do after
Apply it via Angular router links and component inputs to populate forms while tolerating missing optional values.
How it connects
Connects route parameters with URL matrix notation, router links, component inputs, and data-model initialization.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.