Skip to content

Redirect

Mika Berglund edited this page Feb 13, 2020 · 1 revision

Redirect Component

The Redirect component is used to redirect the user to another location when the component renders.

It is useful for instance in conditional rendering, when rendering different content for users who are not authorized to view the content on the current page. You can then redirect the user to the login screen.

Inheritance

The Redirect component is derived from the BlazoradeComponentBase base class.

Parameters

Name Type Description
Delay int? An optional delay in milliseconds to wait before redirecting the user to the specified Url. If not specified, the user is immediately redirected.
Url string The URL to redirect the user to.

Examples

Redirect to login page

This example shows you how you can use the Redirect component to redirect users not authenticated to the login page when they land on a page that requires authentication.

The code below shows the contents of the App.razor file in an application that has been configured with authentication.

<Router AppAssembly="@typeof(Program).Assembly">
    <Found Context="routeData">
        <AuthorizeRouteView
            RouteData="@routeData"
            DefaultLayout="@typeof(MainLayout)">
            <NotAuthorized>
                <Redirect Url="/Account/SignIn">
                    Redirecting to login page...
                </Redirect>
            </NotAuthorized>
        </AuthorizeRouteView>
    </Found>
</Router>