Last active
May 22, 2022 06:37
-
-
Save usausa/c54162acd562de871f7b7423c0842c73 to your computer and use it in GitHub Desktop.
Blazor router
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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