HxRedirectTo #

Rendering a HxRedirectTo will navigate to a new location.
Can be used in AuthorizeRouteView, Router and similar components to redirect to a login page, error page, or similar.

Sample usage in App.razor #

<CascadingAuthenticationState>
    <Router AppAssembly="@typeof(App).Assembly">
        <Found Context="routeData">
            <AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
                <NotAuthorized>
                    @if (context.User.Identity?.IsAuthenticated != true)
                    {
                        <HxRedirectTo Uri="@($"authentication/login?returnUrl={Uri.EscapeDataString(NavigationManager.Uri)}")" />
                    }
                    else
                    {
                        <HxRedirectTo Uri="errors/NotAuthorized" />
                    }
                </NotAuthorized>
            </AuthorizeRouteView>
            <FocusOnNavigate RouteData="@routeData" Selector="h1" />
        </Found>
        <NotFound>
            <HxRedirectTo Uri="errors/NotFound" />
        </NotFound>
    </Router>
</CascadingAuthenticationState>

Basic usage #

API #

Parameters #

Name Type Description
ForceLoad bool If true, bypasses client-side routing and forces the browser to load the new page from the server, regardless of whether the URI would normally be handled by the client-side router.
Default is false.
Uri string URI to navigate to.
An unhandled error has occurred. Reload 🗙