You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
description: Learn about Blazor app request routing.
4
+
description: Learn about Blazor app request routing with guidance on static versus interactive routing, endpoint routing integration, navigation events, and route templates and constraints for Razor components.
5
5
monikerRange: '>= aspnetcore-3.1'
6
6
ms.author: wpickett
7
7
ms.custom: mvc
8
-
ms.date: 09/23/2025
8
+
ms.date: 09/24/2025
9
9
uid: blazor/fundamentals/routing
10
10
---
11
11
# ASP.NET Core Blazor routing
12
12
13
13
[!INCLUDE[](~/includes/not-latest-version.md)]
14
14
15
-
This article explains Blazor app request routing, including Static versus interactive routing, ASP.NET Core endpoint routing integration,
15
+
This article explains Blazor app request routing with guidance on static versus interactive routing, ASP.NET Core endpoint routing integration, navigation events, and route templates and constraints for Razor components.
16
16
17
17
Routing in Blazor is achieved by providing a route template to each accessible component in the app with an [`@page`](xref:mvc/views/razor#page) directive. When a Razor file with an `@page` directive is compiled, the generated class is given a <xref:Microsoft.AspNetCore.Mvc.RouteAttribute> specifying the route template. At runtime, the router searches for component classes with a <xref:Microsoft.AspNetCore.Mvc.RouteAttribute> and renders whichever component has a route template that matches the requested URL.
18
18
19
19
The following `HelloWorld` component uses a route template of `/hello-world`, and the rendered webpage for the component is reached at the relative URL `/hello-world`.
The preceding component loads in the browser at `/hello-world` regardless of whether or not you add the component to the app's UI navigation.
29
+
The preceding component loads in the browser at `/hello-world` regardless of whether or not you add the component to the app's UI navigation as a link.
60
30
61
31
:::moniker range=">= aspnetcore-8.0"
62
32
@@ -146,41 +116,17 @@ Components support multiple route templates using multiple [`@page` directives](
This page is reached at either <code>/blazor-route</code> or
127
+
<code>/different-blazor-route</code>.
128
+
</p>
129
+
```
184
130
185
131
> [!IMPORTANT]
186
132
> For URLs to resolve correctly, the app must include a `<base>` tag ([location of `<head>` content](xref:blazor/project-structure#location-of-head-and-body-content)) with the app base path specified in the `href` attribute. For more information, see <xref:blazor/host-and-deploy/app-base-path>.
@@ -360,41 +306,18 @@ The router uses route parameters to populate the corresponding [component parame
protected override void OnParametersSet() => Text = Text ?? "fantastic";
348
+
}
349
+
```
448
350
449
351
When the [`OnInitialized{Async}` lifecycle method](xref:blazor/components/lifecycle#component-initialization-oninitializedasync) is used instead of the [`OnParametersSet{Async}` lifecycle method](xref:blazor/components/lifecycle#after-parameters-are-set-onparameterssetasync), the default assignment of the `Text` property to `fantastic` doesn't occur if the user navigates within the same component. For example, this situation arises when the user navigates from `/route-parameter-2/amazing` to `/route-parameter-2`. As the component instance persists and accepts new parameters, the `OnInitialized` method isn't invoked again.
450
352
@@ -469,8 +371,6 @@ In the following example, the route to the `User` component only matches if:
469
371
```razor
470
372
@page "/user/{Id:int}"
471
373
472
-
<PageTitle>User</PageTitle>
473
-
474
374
<h1>User Example</h1>
475
375
476
376
<p>User Id: @Id</p>
@@ -568,29 +468,18 @@ Consider the following `Example` component that can receive a route parameter fr
0 commit comments