@inject NavigationManager NavigationManager
@using Microsoft.AspNetCore.Components.Authorization
<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(Program).Assembly">
        <Found Context="routeData">
            <CascadingValue Value="routeData">
                <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(BasicLayout)" >
                    <NotAuthorized>
                        您没有权限访问此页面
                    </NotAuthorized>
                    <Authorizing>
                        <RouteView RouteData="@routeData" DefaultLayout="@typeof(BasicLayout)" />
                    </Authorizing>
                    </AuthorizeRouteView>
            </CascadingValue>
        </Found>
        <NotFound>
            <LayoutView Layout="@typeof(BasicLayout)">
                <AntSK.Pages.Exception._404 />
            </LayoutView>

        </NotFound>
    </Router>
    <AntContainer />
</CascadingAuthenticationState>

@code {
    private RenderFragment RedirectToLogin => builder =>
    {
        var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
        if (string.IsNullOrWhiteSpace(returnUrl))
        {
            NavigationManager.NavigateTo("user/login");
        }
        else
        {
            NavigationManager.NavigateTo($"user/login?returnUrl={Uri.EscapeDataString(returnUrl)}", true);
        }
    };
}
