无路由的Blazor授权

无路由的Blazor授权,blazor,Blazor,我们正在开发一个Blazor应用程序,它不使用内置路由(我们已经实现了自己的路由以满足应用程序的要求)。我们可以使用面向布局的代码添加授权,但是在没有路由的情况下很难定位示例代码 我们可以得到授权与之合作 <CascadingAuthenticationState> <Router AppAssembly="@typeof(Discovery).Assembly" AdditionalAssemblies="@GetAssemblies()&quo

我们正在开发一个Blazor应用程序,它不使用内置路由(我们已经实现了自己的路由以满足应用程序的要求)。我们可以使用面向布局的代码添加授权,但是在没有路由的情况下很难定位示例代码

我们可以得到授权与之合作

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Discovery).Assembly" AdditionalAssemblies="@GetAssemblies()">
    <Found Context="routeData">
        <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
            <NotAuthorized>
                @{
                    var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
                    NavigationManager.NavigateTo($"login?redirectUri={returnUrl}", forceLoad: true);
                }
            </NotAuthorized>
            <Authorizing>
                Wait...
            </Authorizing>
        </AuthorizeRouteView>
    </Found>
    <NotFound>
        <LayoutView Layout="@typeof(MainLayout)">
            <p>Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</Router>

@{
var returnUrl=NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.NavigateTo($“login?redirectUri={returnUrl}”,forceLoad:true);
}
等待
对不起,这个地址什么也没有

但是,当我们删除路由并尝试用固定组件替换时,auth服务就会陷入重定向循环

<CascadingAuthenticationState>
    <AuthorizeView>
        <Authorized>
            <MyComponent></MyComponent>
        </Authorized>
        <NotAuthorized>
            @{
                var returnUrl = NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
                NavigationManager.NavigateTo($"login?redirectUri={returnUrl}", forceLoad: true);
            }
        </NotAuthorized>
        <Authorizing>
            Wait...
        </Authorizing>
    </AuthorizeView>
</CascadingAuthenticationState>

@{
var returnUrl=NavigationManager.ToBaseRelativePath(NavigationManager.Uri);
NavigationManager.NavigateTo($“login?redirectUri={returnUrl}”,forceLoad:true);
}
等待
如果有人能告诉我哪里出了问题,我将不胜感激