'Blazor WASM layout issue with Azure AD

I've integrated my Blazor wasm system with Azure AD to authenticate user identity. I've followed the Microsoft example to set it up. But most of the examples are authenticate in main layout (which have the menu layout), then only redirect to Microsoft login form.

How to authenticate in login layout (manual customize) before land to main layout?

Below is my code.

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
         <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
            <NotAuthorized>
            @if (!context.User.Identity.IsAuthenticated)
            {
            <RedirectToLogin />
            }
            else
            {
            <p>You are not authorized to access this resource.</p>
            }
            </NotAuthorized>
            </AuthorizeRouteView>
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source