In a Blazor server application I have the following code in markup part:
@if (_patientId == 0 || AppState == null || AppState.SelectedPatient == null || AppState.SelectedPatient.PatientId == 0)
{
nm.NavigateTo("/patientlist");
}
else
{
//do something else
}
and in OninitilizeAsync, I have:
protected override async Task OnInitializedAsync()
{
if (_patientId == 0 || AppState == null || AppState.SelectedPatient == null || AppState.SelectedPatient.PatientId == 0)
{
nm.NavigateTo("/patientlist");
}
}
Do I need to have this check both in the markup part and the OnInitializedAsync? The intent is that if the component receives an invalid patient id, the user should be redirected to another page. Is it safe to remove the navigation from the markup part and just let OnInit handle it? Will I run into any exceptions?