Disabling the Back Button in Blazor

Viewed 3275

In a Blazor based SPA, you must be able to stop the user navigating back using the back button in the browser. However, I can't find any information about how to do this.

In classic ASPX this was relatively simple, but how do you do it on a Blazor Application/Page? I've seen [NoCache] on Views, but that doesn't seem to apply to Blazor pages/components. The javascript window.history.forward() option sort of works, but it refreshes the page, and thus loses the form changes.

2 Answers

I'm providing an answer to this question because it gets a lot of views: that suggests a lot of people are searching for an answer to the question.

Since I first asked the question I've worked on various solutions. There's no perfect solution, but I've put together a Gist here. The solution is far too big for a StackOverflow answer.

Related