Hash-based routes
Keep application routes in the URL fragment, with support for nested routes and applications hosted beneath a base path.
Hash-fragment routing for Blazor WebAssembly, so navigation and page refreshes work when the host cannot serve nested routes.
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.
Keep application routes in the URL fragment, with support for nested routes and applications hosted beneath a base path.
Intercept internal navigation and convert links to the configured hash format.
Register the library through dependency injection and initialise routing before the application starts.
Use the URL fragment for routing so the server only needs to serve the application root and static assets.
Document how hash prefixes, base paths and relative links affect navigation.
Support browser-hosted Blazor WebAssembly. Blazor Server and Hybrid have different hosting requirements.
Available as the Blazor.HashRouting NuGet package under the MIT licence. The repository documents setup, URL behaviour and supported environments.