Route Parameters in ASP.NET Core Blazor
@page "/RouteParameter/{text}"
<h1>Blazor is @Text!</h1>
@code {
[Parameter]
public string? Text { get; set; }
}
Optional parameters
@page "/RouteParameter/{text?}"
<h1>Blazor is @Text!</h1>
@code {
[Parameter]
public string? Text { get; set; }
protected override void OnInitialized()
{
Text = Text ?? "fantastic";
}
}
Permit app navigation to the same component with a different optional parameter value
protected override void OnParametersSet()
{
Text = Text ?? "fantastic";
}
References
https://docs.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing#route-parameters
https://docs.microsoft.com/en-us/aspnet/core/blazor/components/#route-parameters
https://blazor-university.com/routing/route-parameters/
https://blazor-university.com/routing/optional-route-parameters/