How is a Blazor app's root wired up: what are the roles of App.razor, the Routes/Router component, and MapRazorComponents?
Last updated
App.razoris the root component: in .NET 8+ it renders the full HTML document and hosts<Routes />plus script references.The
Router(usually inRoutes.razor) maps URLs to@pagecomponents:Foundrenders the page viaRouteViewwith a default layout, andNotFoundhandles unmatched URLs.MapRazorComponents<App>()inProgram.csregisters the root component as an endpoint and enables render modes (e.g.AddInteractiveServerRenderMode()).
- https://learn.microsoft.com/en-us/aspnet/core/blazor/project-structure?view=aspnetcore-10.0
- https://learn.microsoft.com/de-de/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-10.0
- https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-10.0
- https://github.com/dotnet/aspnetcore/issues/47312
- https://www.telerik.com/blogs/unified-blazor-web-app-project-template-fully-explained
- https://blazor-university.com/routing/defining-routes/
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/render-modes?view=aspnetcore-10.0