Quantcast
Channel: Active questions tagged blazor - Stack Overflow
Viewing all articles
Browse latest Browse all 4063

Why doesn't NavigationManager.Uri seem to update itself on .NavigateTo(string)?

$
0
0

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);    }

Viewing all articles
Browse latest Browse all 4063

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>