Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to refresh page in Blazor development process after code changing

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?

like image 320
Viacheslav Avatar asked Jun 26 '20 10:06

Viacheslav


People also ask

How do you refresh a page in Blazor?

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.

How do you force reload a component in Blazor?

To force a component to rerender, use the “StateHasChanged” method in Blazor, to notify that the state has been changed and requires re-rendering.

How do I navigate to another page in Blazor?

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.

What is @page in Blazor?

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.


1 Answers

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.

like image 140
Marco Avatar answered Oct 11 '22 23:10

Marco