Routing in Blazor WebAssembly
Understand how Blazor WebAssembly handles client-side routing by intercepting navigation and rendering matched components. Learn to use route parameters, simulate optional parameters with multiple @page directives, and apply route constraints to enforce data types. Explore catch-all parameters to capture complex paths and improve app navigation.
We'll cover the following...
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:
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:
Route parameters
The Router component uses route parameters to ...