Blazor component routing selects which Razor component to display as the URL changes. It uses ASP.NET Core routing, but a Router component handles selection within the Blazor application, allowing different components to appear without a new HTTP connection. section 35.0 section 35.2
Listing 35.3 The contents of the Routed.razor file in the Blazor folder
<Router AppAssembly="typeof(Program).Assembly">
<Found>
<RouteView RouteData="@context" />
</Found>
<NotFound>
<h4 class="bg-danger text-white text-center p-2">
No Matching Route Found
</h4>
</NotFound>
</Router>
In Routed.razor, AppAssembly identifies the assembly to search. Found passes the matched RouteData to RouteView; NotFound displays a message when no component matches. section 35.2
The pieces have separate jobs:
- Set AppAssembly on Router, commonly to typeof(Program).Assembly, so it can find routable components. section 35.2
- Define component routes with @page; put RouteView in Found to display the matched component and support shared content through layouts. section 35.2 section 35.5
- Provide NotFound content for an unmatched URL, and use NavLink to navigate between routed components. section 35.2 section 35.5
Do not confuse Router with the endpoint-routing middleware that matches an HTTP request to an endpoint. Router bridges that routing system to Blazor component display; RouteView performs the rendering for a match. section 13.1.1 section 35.2





















