If I do the following:
@page "/mypage"@inject NavigationManager NavigationManager<button @onclick="ts">nav to a random fragment</button>@code{ private void ts() { NavigationManager.NavigateTo($"/mypage#{Guid.NewGuid()}"); StateHasChanged(); Console.WriteLine(NavigationManager.Uri); }}
I expect to see a different Guid in both the browser URL bar and in the console every time I click the button. I actually see that the browser URL changes properly but the URL written to the console never does.
Why is NavigationManager.Uri seemingly blatantly wrong? What can I do to get the current URL after I've changed its fragment?
I also tried modifying ts() to the following, which didn't help.
private async Task ts() { NavigationManager.NavigateTo($"admin/unit#{Guid.NewGuid()}"); StateHasChanged(); await Task.Delay(1); Console.WriteLine(NavigationManager.Uri); }