Blazor Interactive Server app. In my MainLayout.razor, if a user is logged in, I display their avatar in the top of the page. Well below that is the @Body
.
If the user changes their avatar, I need to re-render that header component, or the entire page. This change occurs when clicking Submit in the AccountProfile page. At the bottom of that page I have:
<ConfirmNavigation HasUnsavedChanges="@HasUnsavedChanges" />
And ConfirmNavigation.razor is:
<NavigationLock ConfirmExternalNavigation="@HasUnsavedChanges"
OnBeforeInternalNavigation="OnBeforeInternalNavigation" />
Here’s what I’ve been doing. If the avatar is changed, then I set reloadPage
to true and the end of my Submit handler is:
HasUnsavedChanges = false;
await Task.Delay(reloadPage ? 20 : 1);
StateHasChanged();
await Task.Delay(reloadPage ? 20 : 1);
Navigation.NavigateTo(gotoUrl, reloadPage);
The problem is. ConfirmExternalNavigation
does not see that HasUnsavedChanges
is now false and prompts the user asking if they want to leave the site.
My question is not how to have NavigationLock
know there’s no changes. It’s how do I re-render the header part of MainLayout without getting that prompt.