Search⌘ K
AI Features

Blazor Routing to Page Components

Explore how to create routable page components in Blazor by using the @page directive and NavigationManager. Learn to handle route parameters, set layouts, and implement navigation with the NavLink component. This lesson equips you to build interactive, navigable Blazor applications efficiently.

The Router component that we saw in the App.razor file enables routing to components. The markup for creating an instance of a component looks like an HTML tag where the tag's name is the component type. Components can be embedded on a web page using an element, for example, <RatingStars="5" />, or they can be routed to, like a Razor Page or MVC controller.

Routable page component

To create a routable page component, add the @page directive to the top of a component’s .razor file, as shown in the following markup:

C#
@page "customers"

The preceding code is the equivalent of an MVC controller decorated with the [Route] attribute, ...