You can redirect to a page in Blazor using the Navigation Manager’s NavigateTo method. In the following code snippet, it will redirect to the home page when this page gets loaded. Similarly, you can call NavigateTo() method from NavigationManager class anywhere to redirect to another page.
Refer to the following code snippet.
@page "/redirect"
@inject NavigationManager NavManager
<h1>Redirect Page</h1>
<p>Redirecting to Default Page</p>
@code {
protected override void OnInitialized()
{
NavManager.NavigateTo("/");
}
}
Share with