How does Blazor's routing system integrate with ASP.NET Core's endpoint routing, and can they coexist for the same URL space?
Short answer
Blazor's component (configured in App.razor) handles client-side navigation for @page-decorated components, while MapRazorComponents () registers this into ASP.NET Core's endpoint routing system alongside MapControllers()/MapRazorPages() -- URL conflicts between a Blazor @page…
Advertisement
AModel answer
Blazor's <Router> component (configured in App.razor) handles client-side navigation for @page-decorated components, while MapRazorComponents<App>() registers this into ASP.NET Core's endpoint routing system alongside MapControllers()/MapRazorPages() -- URL conflicts between a Blazor @page route and an MVC controller route for the same path are possible and must be avoided by careful route design, since both ultimately compete for the same incoming request routing decision at the ASP.NET Core level.
// Blazor component route
@page "/products/{id:int}"
// MVC controller route -- would conflict if pointing to the same path pattern
[Route("products/{id}")]
public class ProductsController : Controller { }
// Both registered in the same app risk ambiguous routing -- design URL spaces to avoid overlapReal-world example
A team migrating specific pages from MVC to Blazor carefully partitions URL space (e.g., /app/* for new Blazor pages, everything else remaining on existing MVC routes) to avoid any routing ambiguity between the two systems running in the same application.
Likely follow-ups
- How does ASP.NET Core's routing system resolve an ambiguous match between a Blazor and MVC route?
- What's a clean strategy for gradually migrating URL space from MVC to Blazor?
Related topics