asp.net-coreblazor-server-side

NavigationError on NavigateTo


I'm trying out Blazor ServerSide and created a Component to Redirect To the Login Page when a user is not logged in.

@inject Microsoft.AspNetCore.Components.NavigationManager NavigationManager;

@code {
/// <inheritdoc />
protected override Task OnInitializedAsync()
{
    NavigationManager.NavigateTo("Login");
    return Task.CompletedTask;
}

}

But always when "NavigateTo" is called the following exception is thrown:

"Microsoft.AspNetCore.Components.NavigationException: Exception of type 'Microsoft.AspNetCore.Components.NavigationException' was thrown.
   at Microsoft.AspNetCore.Components.Server.Circuits.RemoteNavigationManager.NavigateToCore(String uri, Boolean forceLoad)
   at Microsoft.AspNetCore.Components.NavigationManager.NavigateTo(String uri, Boolean forceLoad)
   at ApplySupportTool.Blazor.Pages.RedirectToLogin.OnInitializedAsync() in C:\\Users\\padruttn\\Documents\\git\\ApplySupportTool\\src\\ApplySupportTool.Blazor\\Pages\\RedirectToLogin.razor:line 8"

Interesstingly the navigation is made despite the exception. I also tried to call it with the path "/login" but the same behaviour here.


Solution

  • There is an open issue on github for this problem. See also the preceeding issue where a possible workaround is mentioned: putting the NavigateTo method into OnAfterRender instead of OnInitialized.