Blazor WASM redirect to page after login

Viewed 508

In my Blazor wasm app I have a default landing page for unauthorized access. I would like to redirect to another page after a successful login.

Have been looking at the RedirectToLogin.razor page. Adding /Holidays after the uri but it's not working.

protected override void OnInitialized()
{
    Navigation.NavigateTo($"authentication/login?returnUrl={Uri.EscapeDataString(Navigation.Uri)}");
}

Have also tried this. It kind of works but the page are loaded twice because blazor has not finished the login process.

@page "/authentication/{action}"
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
@inject NavigationManager Navigation
<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded="@RedirectToHolidayViewer" />

@code{
[Parameter] public string Action { get; set; }

private void RedirectToHolidayViewer()
{
    // this code will be hit twice 
    state.ReturnUrl = "/Holidays";
}

}

0 Answers
Related