Routing in Blazor WebAssembly

Learn how routing works in Blazor WebAssembly.

In Blazor WebAssembly, routing is handled on the client, not on the server. As we navigate in the browser, Blazor intercepts that navigation and renders the component with the matching route.

The URLs are resolved relative to the base path that is specified in the wwwroot/index.html file. It is specified in the head element using the following syntax:

Press + to interact
<base href="/" />

Unlike other frameworks that we may have used, the route is not inferred from the location of its file. For example, in the Demo project, the Counter component is in the /Pages/Counter folder, yet it uses the following route:

Press + to interact
@page "/counter"

Route

...