---
title: ASP.NET Core Blazor routing
author: guardrex
description: Learn how to route requests in apps and about the NavLink component.
monikerRange: '>= aspnetcore-3.0'
ms.author: riande
ms.custom: mvc
ms.date: 10/15/2019
no-loc: [Blazor]
uid: blazor/routing
---
# ASP.NET Core Blazor routing
By [Luke Latham](https://github.com/guardrex)
[!INCLUDE[](~/includes/blazorwasm-preview-notice.md)]
Learn how to route requests and how to use the `NavLink` component to create navigation links in Blazor apps.
## ASP.NET Core endpoint routing integration
Blazor Server is integrated into [ASP.NET Core Endpoint Routing](xref:fundamentals/routing). An ASP.NET Core app is configured to accept incoming connections for interactive components with `MapBlazorHub` in `Startup.Configure`:
[!code-csharp[](routing/samples_snapshot/3.x/Startup.cs?highlight=5)]
The most typical configuration is to route all requests to a Razor page, which acts as the host for the server-side part of the Blazor Server app. By convention, the *host* page is usually named *_Host.cshtml*. The route specified in the host file is called a *fallback route* because it operates with a low priority in route matching. The fallback route is considered when other routes don't match. This allows the app to use others controllers and pages without interfering with the Blazor Server app.
## Route templates
The `Router` component enables routing to each component with a specified route. The `Router` component appears in the *App.razor* file:
```cshtml
Sorry, there's nothing at this address.
```
When a *.razor* file with an `@page` directive is compiled, the generated class is provided a specifying the route template.
At runtime, the `RouteView` component:
* Receives the `RouteData` from the `Router` along with any desired parameters.
* Renders the specified component with its layout (or an optional default layout) using the specified parameters.
You can optionally specify a `DefaultLayout` parameter with a layout class to use for components that don't specify a layout. The default Blazor templates specify the `MainLayout` component. *MainLayout.razor* is in the template project's *Shared* folder. For more information on layouts, see .
Multiple route templates can be applied to a component. The following component responds to requests for `/BlazorRoute` and `/DifferentBlazorRoute`:
[!code-cshtml[](common/samples/3.x/BlazorWebAssemblySample/Pages/BlazorRoute.razor?name=snippet_BlazorRoute)]
> [!IMPORTANT]
> For URLs to resolve correctly, the app must include a `` tag in its *wwwroot/index.html* file (Blazor WebAssembly) or *Pages/_Host.cshtml* file (Blazor Server) with the app base path specified in the `href` attribute (``). For more information, see .
## Provide custom content when content isn't found
The `Router` component allows the app to specify custom content if content isn't found for the requested route.
In the *App.razor* file, set custom content in the `NotFound` template parameter of the `Router` component:
```cshtml
The browser is forced to load the new page from the server, whether or not the URI is normally handled by the client-side router.
|
| `LocationChanged` | An event that fires when the navigation location has changed. |
| `ToAbsoluteUri` | Converts a relative URI into an absolute URI. |
| `ToBaseRelativePath` | Given a base URI (for example, a URI previously returned by `GetBaseUri`), converts an absolute URI into a URI relative to the base URI prefix. |
The following component navigates to the app's `Counter` component when the button is selected:
```cshtml
@page "/navigate"
@inject NavigationManager NavigationManager