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

Blazor replace URL in browser history

$
0
0

Is there a way in Blazor routing to replace the URL link when navigating to another page? Something similar to window.location.replace in JS, or the replace attribute in React's "Link" tag, or React's history.replace?I don't want to have a history item with every navigation in the application..

Update: I tried the following in the index page, but no avail:

@inject IJSRuntime js@inject NavigationManager NavigationManagerprotected override void OnInitialized()    {        NavigationManager.LocationChanged += LocationChanged;        base.OnInitialized();    }    private void LocationChanged(object sender, LocationChangedEventArgs e)    {        js.InvokeVoidAsync("replace", e.Location);    }

And the js function is:

function replace(url) {    window.location.replace(url);}

Viewing all articles
Browse latest Browse all 4839

Trending Articles



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