I have a blazor app page, and when i go there by the link from another page, it works and i can see h1 header with correct value, but if i will click F5 or call reloadpage method, it throws NullReferenceException on line with h1 header, like item object is null. How can i avoid that behaviour?
...
@inject NavigationManager MyNavigationManager
@page "/items/{id}"
...
<h1>@_item.Name<h1>
...
[Parameter]
public string Id { get; set; }
private Item _item;
protected override async Task OnInitializedAsync()
{
_item= await ItemsService.GetItem(Id);
}
private void ReloadPage(bool forceLoad = false)
{
MyNavigationManager.NavigateTo($"/items/{Id}", forceLoad);
}