在显示重定向页面之前显示默认页面
Default page is displayed before displaying redirected page
我有一个服务器端应用程序可以重定向到另一个应用程序以进行登录和注册。所以在 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>
和重定向组件:
public class RedirectToLogin : ComponentBase
{
protected override void OnInitialized()
{
base.OnInitialized();
//here navigateto....
}
}
这部分有效,因为我确实被重定向了,但是,最初显示的是默认主页。
是否可以更改此行为,以便在主页 loaded/shown 之前进行重定向?
我认为您需要编辑 mainlayout.razor 页面并在其中添加您的控件 RedirectToLogin,因为 Blazor 有一个默认的 RedirectToLogin.razor 控件,该控件也将重定向到默认的 Authentication.razor。请检查此
我有一个服务器端应用程序可以重定向到另一个应用程序以进行登录和注册。所以在 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>
和重定向组件:
public class RedirectToLogin : ComponentBase
{
protected override void OnInitialized()
{
base.OnInitialized();
//here navigateto....
}
}
这部分有效,因为我确实被重定向了,但是,最初显示的是默认主页。
是否可以更改此行为,以便在主页 loaded/shown 之前进行重定向?
我认为您需要编辑 mainlayout.razor 页面并在其中添加您的控件 RedirectToLogin,因为 Blazor 有一个默认的 RedirectToLogin.razor 控件,该控件也将重定向到默认的 Authentication.razor。请检查此