The short answer to Blazor how to redirect is the built-in NavigationManager service. Inject it into the component and call NavigateTo with the page you want:
@inject NavigationManager Nav
<button @onclick='() => Nav.NavigateTo("/orders")'>View orders</button>
The same service gives you the current URL (Nav.Uri) and reloads the page (Nav.Refresh(true)). I tested each snippet below in a .NET 10 Blazor Web App on localhost, so the URLs, logs and status codes are real.
NavigateTo Syntax: How to Redirect in Blazor
NavigationManager is registered by the framework, so there’s nothing to add to Program.cs. These are the members you’ll use, checked against the .NET 10 docs:
| Member | What it does |
|---|---|
NavigateTo(uri) | Goes to the URL, with enhanced (no full reload) navigation when it’s available |
NavigateTo(uri, forceLoad: true) | Skips client-side routing and loads the page from the server |
NavigateTo(uri, replace: true) | Replaces the current history entry instead of adding one |
NavigateTo(uri, new NavigationOptions { ... }) | Same switches as properties, plus HistoryEntryState |
Refresh(forceReload: true) | Reloads the current page |
Uri / BaseUri | The current absolute URL / the app’s base URL |
A relative URL like orders/1042 is resolved against BaseUri, not the current page. The API is identical whether the component runs on the server or in the browser (see Blazor Server vs WebAssembly).
Set Up the Blazor Demo App
My sample is an orders portal for Cascade Outfitters, a Seattle outdoor store. It’s the standard template from the Blazor tutorial for beginners, created on SDK 10.0.402:
dotnet new blazor -n W14NavApp
The .NET 10 template already adds one line to the project file that matters for redirects, BlazorDisableThrowNavigationException. More on it below:
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net10.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<BlazorDisableThrowNavigationException>true</BlazorDisableThrowNavigationException>
</PropertyGroup>
</Project>
I deleted appsettings.Development.json, kept appsettings.json, and pointed the http profile at port 5922:
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
}
{
"$schema": "https://json.schemastore.org/launchsettings.json",
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": false,
"applicationUrl": "http://localhost:5922",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Program.cs is the template’s file minus the HTTPS and error-page middleware, since the demo only runs on http:
using W14NavApp.Components;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddRazorComponents()
.AddInteractiveServerComponents();
var app = builder.Build();
app.UseStatusCodePagesWithReExecute("/not-found", createScopeForStatusCodePages: true);
app.UseAntiforgery();
app.MapStaticAssets();
app.MapRazorComponents<App>()
.AddInteractiveServerRenderMode();
app.Run();
How to Get the Current URL in Blazor (Nav.Uri, BaseUri, ToBaseRelativePath)
Here’s the full Orders.razor page. The table at the top prints the three URL values, and the buttons cover the next few sections. It uses @rendermode InteractiveServer so the buttons work (see Blazor render modes):
@page "/orders"
@rendermode InteractiveServer
@implements IDisposable
@using System.Globalization
@inject NavigationManager Nav
<PageTitle>Orders</PageTitle>
<h1>Cascade Outfitters - Orders</h1>
<table class="table table-sm w-auto">
<tr><th>Nav.Uri</th><td>@Nav.Uri</td></tr>
<tr><th>Nav.BaseUri</th><td>@Nav.BaseUri</td></tr>
<tr><th>ToBaseRelativePath</th><td>@Nav.ToBaseRelativePath(Nav.Uri)</td></tr>
<tr><th>State (query)</th><td>@(State ?? "(all)")</td></tr>
</table>
<button id="wa" class="btn btn-primary" @onclick="ShowWashington">Washington</button>
<button id="or" class="btn btn-outline-primary" @onclick="ShowOregon">Oregon (replace)</button>
<button id="open" class="btn btn-outline-secondary" @onclick="OpenOrder">Order 1042</button>
<button id="reload" class="btn btn-outline-danger" @onclick="ReloadPage">Reload page</button>
<ul class="mt-3">
@foreach (var o in Shown)
{
<li>#@o.Id @o.Customer, @o.City, @o.State: @o.Total.ToString("C", Us)</li>
}
</ul>
@code {
[SupplyParameterFromQuery]
private string? State { get; set; }
private static readonly CultureInfo Us = CultureInfo.GetCultureInfo("en-US");
private record Order(int Id, string Customer, string City, string State, decimal Total);
private static readonly Order[] All =
[
new(1041, "Jenna Morales", "Seattle", "WA", 129.99m),
new(1042, "Tyler Brooks", "Spokane", "WA", 84.50m),
new(1043, "Dana Whitfield", "Portland", "OR", 212.00m),
new(1044, "Marcus Reed", "Austin", "TX", 56.25m),
];
private IEnumerable<Order> Shown => State is null ? All : All.Where(o => o.State == State);
protected override void OnInitialized() => Nav.LocationChanged += OnLocationChanged;
private void ShowWashington() =>
Nav.NavigateTo(Nav.GetUriWithQueryParameter("state", "WA"));
private void ShowOregon() =>
Nav.NavigateTo(Nav.GetUriWithQueryParameter("state", "OR"),
new NavigationOptions { ReplaceHistoryEntry = true });
private void OpenOrder() => Nav.NavigateTo("orders/1042");
private void ReloadPage() => Nav.Refresh(forceReload: true);
private void OnLocationChanged(object? sender, LocationChangedEventArgs e) =>
Console.WriteLine($"[nav] LocationChanged: {e.Location} (intercepted: {e.IsNavigationIntercepted})");
public void Dispose() => Nav.LocationChanged -= OnLocationChanged;
}
I opened /orders in Edge and clicked Washington:

Nav.Uri is the full address, http://localhost:5922/orders?state=WA. BaseUri always ends in a slash, and ToBaseRelativePath(Nav.Uri) returns orders?state=WA, the piece you’d store as a return URL.
Redirect With a Query String (GetUriWithQueryParameter)
ShowWashington doesn’t build the string by hand. GetUriWithQueryParameter takes the current URL and adds, changes or removes one parameter:
Nav.NavigateTo(Nav.GetUriWithQueryParameter("state", "WA"));
On the receiving side, [SupplyParameterFromQuery] fills State from ?state=WA. It works like a regular component parameter, so the list re-filtered to the two Washington orders: Jenna Morales ($129.99) and Tyler Brooks ($84.50).
Passing null as the value removes the parameter. For several at once, use GetUriWithQueryParameters.
Redirect Without Adding a History Entry (NavigationOptions)
By default each NavigateTo adds a history entry, so the Back button walks through every filter. The Oregon (replace) button passes ReplaceHistoryEntry = true:
Nav.NavigateTo(Nav.GetUriWithQueryParameter("state", "OR"),
new NavigationOptions { ReplaceHistoryEntry = true });
I logged history.length in headless Edge after each click:
| Click | URL | history.length |
|---|---|---|
| (page load) | /orders | 2 |
| Washington | /orders?state=WA | 3 |
| Oregon (replace) | /orders?state=OR | 3 |
| Order 1042 | /orders/1042 | 4 |
The Oregon click changed the URL but not the count, so when you press Back, you skip the Washington view. In .NET 10, NavigationOptions has three properties: ForceLoad, ReplaceHistoryEntry and HistoryEntryState (a string saved with the entry).
How Do I Refresh the Page in Blazor?
Call Refresh. Without arguments it does an enhanced navigation when it can, which re-renders the page without a full browser reload. Pass true to force a real reload, like the Reload page button:
private void ReloadPage() => Nav.Refresh(forceReload: true);
To prove it, I set a JavaScript variable before clicking. After the click it was undefined, the browser reported the navigation type as reload, and the SignalR circuit reconnected with a new id.
The older way, Nav.NavigateTo(Nav.Uri, forceLoad: true), still works. Refresh just says what you mean.
Track URL Changes With the LocationChanged Event
Orders.razor subscribes to LocationChanged in OnInitialized and unsubscribes in Dispose, so the handler doesn’t outlive the page. This is what the terminal printed for my three clicks:
[nav] LocationChanged: http://localhost:5922/orders?state=WA (intercepted: False)
[nav] LocationChanged: http://localhost:5922/orders?state=OR (intercepted: False)
[nav] LocationChanged: http://localhost:5922/orders/1042 (intercepted: False)

IsNavigationIntercepted is False because NavigateTo caused each one; a clicked link that Blazor intercepts reports True. If the handler changes what’s on screen, wrap the update in InvokeAsync as shown in StateHasChanged not refreshing.
Redirect in OnInitialized: Static SSR Returns a 302
Retiring an old URL is the common case. OldOrders.razor has no render mode, so it renders with static SSR and redirects in OnInitialized, the first method in the component lifecycle:
@page "/old-orders"
@inject NavigationManager Nav
@code {
protected override void OnInitialized()
{
Console.WriteLine("[nav] /old-orders requested, redirecting");
Nav.NavigateTo("orders?state=TX");
Console.WriteLine("[nav] code after NavigateTo ran");
}
}
I requested the page with curl, which doesn’t follow redirects:
curl -i http://localhost:5922/old-orders
HTTP/1.1 302 Found
Location: http://localhost:5922/orders?state=TX
No page HTML, no SignalR circuit: the server answers with a real 302 and a Location header. The terminal shows something else worth knowing:
[nav] /old-orders requested, redirecting
[nav] code after NavigateTo ran

Before .NET 10, NavigateTo threw a NavigationException during static SSR and the framework turned it into the redirect. The new BlazorDisableThrowNavigationException property switches that off, and the .NET 10 template sets it to true.
I flipped it to false and ran the same request:
| BlazorDisableThrowNavigationException | Response | Line after NavigateTo |
|---|---|---|
true (.NET 10 template) | 302 to /orders?state=TX | Ran |
false (older behavior) | 302 to /orders?state=TX | Skipped (exception) |
Important: with the property on, add a return after NavigateTo if the rest of the method shouldn’t run. In an interactive component, NavigateTo doesn’t throw at all.
Redirect to the Login Page With a returnUrl
The same pattern sends anonymous users to sign in and remembers where they were. Account.razor reads the cascaded HttpContext, which is only available during static SSR:
@page "/account"
@inject NavigationManager Nav
<h1>My account</h1>
@code {
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
protected override void OnInitialized()
{
if (HttpContext?.User.Identity?.IsAuthenticated != true)
{
var returnUrl = Uri.EscapeDataString(Nav.ToBaseRelativePath(Nav.Uri));
Nav.NavigateTo($"login?returnUrl={returnUrl}");
}
}
}
@page "/login"
@inject NavigationManager Nav
<PageTitle>Sign in</PageTitle>
<h1>Sign in to Cascade Outfitters</h1>
<p>Current URL: <code>@Nav.Uri</code></p>
<p>After you sign in, you go back to: <strong>/@ReturnUrl</strong></p>
@code {
[SupplyParameterFromQuery]
private string? ReturnUrl { get; set; }
}
Requesting /account returned a 302 to /login?returnUrl=account, and the login page read the value back with [SupplyParameterFromQuery]:

Uri.EscapeDataString keeps a return path with its own query string intact. In a real app, [Authorize] and the auth middleware do this check for you (the JWT authentication guide shows that side); the redirect mechanics are the same.
NavLink vs NavigateTo: Which One Should You Use?
<NavLink> | NavigateTo | |
|---|---|---|
| What it is | A link (<a>) in markup | A C# method call |
| Use it when | The user picks where to go | Your code decides (after a save, a check, a filter) |
| Extra | Adds the active CSS class for the current page | Options for reload, history and state |
If you only need a menu link, you don’t need NavigationManager at all. NavLink marks itself active with NavLinkMatch.Prefix by default; use NavLinkMatch.All for the home link so it isn’t always highlighted.
Stop a Redirect When There Are Unsaved Changes (NavigationLock)
The last piece stops a redirect. OrderDetail.razor renders a NavigationLock and cancels internal navigation while there are edits, a handy guard for Blazor forms:
@page "/orders/{Id:int}"
@rendermode InteractiveServer
@inject NavigationManager Nav
<PageTitle>Order @Id</PageTitle>
<h1>Order #@Id</h1>
<p>Current URL: <code>@Nav.Uri</code></p>
<NavigationLock ConfirmExternalNavigation="dirty" OnBeforeInternalNavigation="OnBeforeLeave" />
<button id="edit" class="btn btn-outline-secondary" @onclick="() => dirty = true">Edit shipping note</button>
<button id="back" class="btn btn-primary" @onclick='() => Nav.NavigateTo("orders")'>Back to orders</button>
<p class="mt-3 text-danger">@message</p>
@code {
[Parameter] public int Id { get; set; }
private bool dirty;
private string? message;
private void OnBeforeLeave(LocationChangingContext context)
{
if (!dirty) return;
context.PreventNavigation();
message = $"Unsaved changes: navigation to {context.TargetLocation} was blocked.";
Console.WriteLine($"[nav] NavigationLock blocked {context.TargetLocation}");
}
}
I clicked Edit shipping note, then Back to orders:

The URL stayed on /orders/1042, and context.TargetLocation held orders, the exact string passed to NavigateTo. ConfirmExternalNavigation covers the other exits (closing the tab, typing a new address) with the browser’s own confirm dialog.
Want to keep going with Blazor? These pair well with this one:
- Browse every Blazor tutorial on the site
- Show the order list in a sortable QuickGrid
- Call JavaScript from Blazor when the browser API isn’t wrapped
- Let users download a file from a Blazor page
Frequently Asked Questions
How do I redirect to another page in Blazor?
Inject NavigationManager and call NavigateTo(“/page”). In an interactive component it navigates in the browser; during static SSR it returns a 302 redirect. Microsoft Learn covers the details in ASP.NET Core Blazor navigation.
How do I get the current URL in Blazor?
Read NavigationManager.Uri for the absolute URL and BaseUri for the app root. ToBaseRelativePath(Nav.Uri) gives the relative path, such as orders?state=WA.
How do I refresh the current page in Blazor?
Call Nav.Refresh() for an enhanced refresh or Nav.Refresh(true) for a full browser reload. NavigateTo(Nav.Uri, forceLoad: true) also works.
Why does code after NavigateTo still run in .NET 10?
The .NET 10 Blazor Web App template sets BlazorDisableThrowNavigationException to true, so NavigateTo no longer throws a NavigationException during static SSR. Add a return after the call if the rest of the method shouldn’t run.
What does forceLoad do in NavigateTo?
forceLoad: true skips Blazor’s client-side routing and loads the page from the server, which starts the app fresh in the browser. Use it after sign-in or sign-out, or for pages outside the Blazor router.
How do I stop a user from leaving a Blazor page?
Render a NavigationLock component. Call PreventNavigation() in OnBeforeInternalNavigation to cancel in-app navigation, and set ConfirmExternalNavigation to true for the browser’s confirm dialog.
Bijay Kumar is a renowned software engineer, accomplished author, and distinguished Microsoft Most Valuable Professional (MVP) specializing in SharePoint. With a rich professional background spanning over 15 years, Bijay has established himself as an authority in the field of information technology. He possesses unparalleled expertise in multiple programming languages and technologies such as ASP.NET, ASP.NET MVC, C#.NET, and SharePoint, which has enabled him to develop innovative and cutting-edge solutions for clients across the globe. Read more…