What is the difference between a component and a page in Blazor?
Last updated
Every page in Blazor is a component, but not every component is a page: a page is simply a routable component that has been assigned a URL via the @page directive.
Component:
A reusable, self-contained piece of UI (a
.razorfile) with its own markup, logic, and lifecycle.Rendered by being placed inside another component's markup (e.g.
<Counter />), often receiving data via[Parameter].
Page:
A component with a route template, so the router can navigate to it directly by URL.
Declared with
@page "/counter"; it can also read route parameters and query strings.
Key takeaway: There is no separate "Page" type: a page is just a component that opted into routing. Both are compiled to classes deriving from
ComponentBase.
- https://www.infragistics.com/blogs/blazor-vs-razor
- https://blazor-university.com/components/
- https://www.telerik.com/blogs/blazor-basics-blazor-routing-navigation-fundamentals
- https://learn.microsoft.com/en-us/aspnet/core/blazor/fundamentals/routing?view=aspnetcore-10.0
- https://www.reddit.com/r/Blazor/comments/n3ks85/blazor_components_vs_pages/
- https://learn.microsoft.com/en-us/aspnet/core/blazor/components/?view=aspnetcore-10.0
- https://www.syncfusion.com/blogs/post/blazor-routing-an-overview
- https://blazor-university.com/routing/defining-routes/