For me, a biggest discomfort of Blazor development is absent to simple refreshing page after tiny changing HTML of style in source code. Since ASP.NET was born this opportunity has been present - we changing something in HTML or in code, than simple click refresh in browser and new page instantly was appear in browser. But in Blazor development even after tiny changing code or HTML we must stop web server then start full compilation sourse code again and after compilation has been ended successfully IIS will be started and Browser will be started. And even after that HTML-page will be showing in Browser. In Classic ASP.NET we was have even more faster development method - Designer of Visual Studio with directly showing any HTML-changing. Current Blazor development process slows down speed of Web-development for millions times. Is this possible to restore convenient ASP.NET workflow of web-development in Blazor at least to the MVC development speed (with simple refresh page in Browser without recompliation and restarting all development components after tiny changing of code or HTML?
A page is reloaded/refreshed automatically at a specified interval using “NavigationManager” in OnAfterRender() method. Here the NavigateTo(“url”, forceLoad: true) method, is used to force load the browser based on the URI.
To force a component to rerender, use the “StateHasChanged” method in Blazor, to notify that the state has been changed and requires re-rendering.
You can redirect to a page in Blazor using the Navigation Manager's NavigateTo method. In the following code snippet, it will redirect to the home page when this page gets loaded. Similarly, you can call NavigateTo() method from NavigationManager class anywhere to redirect to another page.
To create a page in Blazor, create a component and add the @page Razor directive to specify the route for the component. The @page directive takes a single parameter, which is the route template to add to that component.
There is a commercial solution called LiveSharp.net which solves most of your problems. They offer a free trial. I personally use it and it really saves a lot of time, especially when doing CSS / HTML tweaking.
In addition, .NET 6 is announced to offer hot reload out of the box.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With