A closer look

Blazor.HashRouting

Hash-fragment routing for Blazor WebAssembly, so navigation and page refreshes work when the host cannot serve nested routes.

Background

Why I started it

A Blazor app can navigate to a page in the browser, then fail when that page is refreshed because the host cannot serve its URL. Some static hosts and proxy setups can only reliably serve the application root.

I built this for qbtmud, then made it available as a standalone library so other Blazor developers could use hash routing in their own applications.

The work

What it offers

Hash-based routes

Keep application routes in the URL fragment, with support for nested routes and applications hosted beneath a base path.

Internal link handling

Intercept internal navigation and convert links to the configured hash format.

Startup integration

Register the library through dependency injection and initialise routing before the application starts.

Implementation

Engineering choices

01

Work with the host

Use the URL fragment for routing so the server only needs to serve the application root and static assets.

02

Make URL behaviour explicit

Document how hash prefixes, base paths and relative links affect navigation.

03

Keep the scope focused

Support browser-hosted Blazor WebAssembly. Blazor Server and Hybrid have different hosting requirements.

Current status

Where it stands

Available as the Blazor.HashRouting NuGet package under the MIT licence. The repository documents setup, URL behaviour and supported environments.