I'm trying to create a Blazor webassambly page where about 8 filter states are stored and synchronised as query parameters.
Currently, the below sample page supports that when I request /orders?status=uploading the status is preset with Uploading and when I choose another value in the InputSelect the state is updated on the Status property on the model.
But further, when choosing another value in the InputSelect, I would like the URL to update to reflect that (without reloading the page).
How is best practices for updating the URL to always reflect the state of the page (with multiple parameters)?
@page "/orders"
<PageTitle>Navigation demo</PageTitle>
<EditForm Model="_model">
<InputSelect @bind-Value="_model.Status">
@foreach (var orderStatus in Enum.GetValues(typeof(OrderStatus)))
{
<option value="@orderStatus">@orderStatus</option>
}
</InputSelect>
</EditForm>
Selected status: @_model.Status
@code {
public enum OrderStatus
{
Created,
Uploading,
Uploaded
}
readonly Model _model = new();
class Model
{
public OrderStatus Status { get; set; }
}
[Parameter]
[SupplyParameterFromQuery(Name = "status")]
public string? StatusString
{
get => _model.Status.ToString();
set
{
var couldParse = Enum.TryParse(value, true, out OrderStatus newStatus);
if (couldParse)
{
_model.Status = newStatus;
}
}
}
}