I normally do not answer questions anymore, but this is one is old and seems that most answers are not correct.
In your OnInitialized, either variety, you need to set a boolean.
Reason event lifecycle is OnInitialized fires then OnAfterRender will fire.
So the clean way to do this is
private bool InitializationFailed = false;
protected override void OnInitialized()
{
InitializationFailed = false;
if (x == 5)
{
InitializationFailed = true;
}
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (InitializationFailed)
{
NavManager.NavigateTo(NavManager.BaseUri);
}
await base.OnAfterRenderAsync(firstRender);
}
That is it and it does work
/dashboardload when you go to the page directly?