在显示重定向页面之前显示默认页面



我有一个服务器端应用程序重定向到另一个应用程序登录&登记。所以在app.razor中,我做了:

<CascadingAuthenticationState>
<Router AppAssembly="@typeof(Program).Assembly" PreferExactMatches="@true">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<NotAuthorized>
<RedirectToLogin/>
</NotAuthorized>
<Authorizing>
<p>Please wait...</p>
</Authorizing>
</AuthorizeRouteView>
</Found>
<NotFound>
<LayoutView Layout="@typeof(MainLayout)">
<p>Sorry, there's nothing at this address.</p>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>

和redirect组件:

public class RedirectToLogin : ComponentBase
{
protected override void OnInitialized()
{
base.OnInitialized();
//here navigateto....
}
}

这部分有效,因为我确实被重定向了,但是,初始显示默认主页。

是否可以更改此行为,以便在加载/显示主页之前发生重定向?

我认为你需要编辑mainlayout。razor页面并在那里添加您的控件RedirectToLogin,因为Blazor有默认的RedirectToLogin。razor控件,它也会重定向到默认的Authentication.razor。请检查这个答案

最新更新