SPA means Single Page Application. In this context, taken literally, it beens that the Blazor app has only one razor page. Here is a way to use just one page but appears to have multiple pages through multiple paths and ASP.NET conditional coding.

Sample Repository

See BlazorSPA on GitHub


A template for a Blazor SPA, with multiple virtual pages.
A Single Page Application.

Demostrates using multiple paths to the one page.
NavMenu is just a menu with each item a different path to the same page.

@page "/"
@page "/Page/First"
@page "/Page/Second"
@page "/Page/Third"

Conditional HTML depending upon the path used.

@if (target == "")
@if (target == "First")
@if (target == "Second")
@if (target == "Third")

Demonstrates use of the MyNavigationManager.LocationChanged event.
Also uses OnInitializedAsync handler as well as the OnInitialized event handler.
OnRendered event handler is also present as well as OnAfterRenderAsync.

The app is a Blazor WASM app with ASP.NET backend, Has PWA enabled.
The server has no special functionality at this stage.

See index.razor for the page coding here as on GitHub.

The following is needed to causes rerendering when the path changes but the page is the same:

    void LocationChanged(object sender, LocationChangedEventArgs e)
        string location = e.Location;

This requires the following hookup in OnInitializedAsync() or in OnInitialized()

    protected override async Task OnInitializedAsync()
        MyNavigationManager.LocationChanged += LocationChanged;

<  Prev:   Blazor
 This Category Links 
Category:Coding Index:Coding
  Next: > .NETCore
<  Prev:   Nuget Packages 101