Skip to content

Update documentation for Optional Parameters in Routing #20591

@gregoryagu

Description

@gregoryagu

This page says "Optional parameters aren't supported."

This is no longer true. See #19733

I have tested and it works great.

For example: @page "/viewpost/{code?}"

routes to the viewpost page for both of these routes:

/viewpost
'viewpost/test'

I have tested this with both SS and CS Blazor and it worked correctly.

Would suggest the following:

Remove this paragraph:

Optional parameters aren't supported. Two @page directives are applied in the previous example. The first permits navigation to the component without a parameter. The second @page directive takes the {text} route parameter and assigns the value to the Text property.

Replace with:

Optional parameters are supported by Blazor on both Server and WebAssemebly appss. Two @page directives are applied in the previous example. To reduce to one, use this syntax: @page "/RouteParameter/{text?}. This will match both /RouteParameter and /RouteParameter/optional. The first route sets the Text parameter to null (or the default value if provided as in this example), while the second route sets it to optional.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions