I created a new Blazor Server Side Application in Preview 8. When I call the UriHelper.NavigateTo to go to the counter page from the Index.razor page, the counter page is c
This behavior is because the pre-render feature. Notice that, when you are on counter page (loaded for twice), if you click on Home, only one execution is fired:
When pre-render is enabled (by default), the prerended page's OnInitializedAsync is called for twice by design. For this reason, your redirect statement is executed for twice.
To test is I wrote this code on index OnInitializedAsync:
@page "/"
@inject IUriHelper UriHelper
Hello, world!
Welcome to your new app.
@code{
protected async override Task OnInitializedAsync()
{
System.Console.WriteLine("_* ");
System.Console.WriteLine("_**************************");
System.Console.WriteLine("_***** Pre render ******");
System.Console.WriteLine("_**************************");
System.Console.WriteLine("_ ");
return;
}
}
And I call the page using pre-render and from the app (without prerender). Noticed that when I force reload (prerended) the OnInitializedAsync is executed for twice:
Learn more about render modes.