I have a component that will pop-up a dialog asking if you're sure you want to discard changes when switching to a different page. I put it on each page as follows:
<ConfirmNavigation HasUnsavedChanges="@HasUnsavedChanges" />And this component includes:
[Parameter]public bool HasUnsavedChanges { get; set; }private async Task OnBeforeInternalNavigation(LocationChangingContext context){ if (!HasUnsavedChanges) return;My problem is that in the parent page, handling the submit click, I have:
HasUnsavedChanges = false;await Task.Delay(1);Navigation.NavigateTo(gotoUrl);That doesn't work. The method returns after those 2 lines of code and ConfirmNavigation still considers HasUnsavedChanges to be true.
Is there a way to do something so that the changed value of HasUnsavedChanges makes it to ConfirmNavigation? Is my best bet to add a method to ConfirmNavigation that sets the value? I dislike that because it is going around the HasUnsavedChanges="@HasUnsavedChanges" which violates how components are supposed to interact.