Skip to content

Instantly share code, notes, and snippets.

@usausa
Last active May 22, 2022 06:37
Show Gist options
  • Save usausa/c54162acd562de871f7b7423c0842c73 to your computer and use it in GitHub Desktop.
Save usausa/c54162acd562de871f7b7423c0842c73 to your computer and use it in GitHub Desktop.
Blazor router
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<ExtendedErrorBoundary @ref="errorBoundary">
<ChildContent>
<ExtendedAuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" NotAuthorizedLayout="@typeof(ErrorLayout)">
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated != true)
{
<Server.Pages.Login Reload="true" />
}
else
{
<Error403 />
}
</NotAuthorized>
</ExtendedAuthorizeRouteView>
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
</ChildContent>
<ErrorContent>
<LayoutView Layout="@typeof(ErrorLayout)">
<Error500 Exception="@context" RecoverRequest="() => errorBoundary.Recover()"/>
</LayoutView>
</ErrorContent>
</ExtendedErrorBoundary>
</Found>
<NotFound>
<LayoutView Layout="@typeof(ErrorLayout)">
<Error404 />
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
@code {
private ErrorBoundary errorBoundary = default!;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment