SpawnDev.BlazorJS.IndexRouting 1.0.0

dotnet add package SpawnDev.BlazorJS.IndexRouting --version 1.0.0                
NuGet\Install-Package SpawnDev.BlazorJS.IndexRouting -Version 1.0.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="SpawnDev.BlazorJS.IndexRouting" Version="1.0.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add SpawnDev.BlazorJS.IndexRouting --version 1.0.0                
#r "nuget: SpawnDev.BlazorJS.IndexRouting, 1.0.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install SpawnDev.BlazorJS.IndexRouting as a Cake Addin
#addin nuget:?package=SpawnDev.BlazorJS.IndexRouting&version=1.0.0

// Install SpawnDev.BlazorJS.IndexRouting as a Cake Tool
#tool nuget:?package=SpawnDev.BlazorJS.IndexRouting&version=1.0.0                

SpawnDev.BlazorJS.IndexRouting

NuGet

Contains IndexRouter, an alternative Route component for Blazor WebAssembly that routes all pages to index.html with the page route stored as a query parameter. This allows hosting methods that do not provide error page redirection, which can cause issues with client-side routing.

Default <Router> rendered url:
https://www.mysite.com/user/42/profile?style=dark

<IndexRouter> rendered url:
https://www.mysite.com/index.html?$=user/42/profile&style=dark

IComponents can use the @page attribute and parameters normally.

Demo

Simple Demo

Getting started

Add the Nuget package SpawnDev.BlazorJS.IndexRouting to your project using your package manager of choice.

Use IndexRouter

Replace <Router> with <IndexRouter> in App.razor

@using SpawnDev.BlazorJS.IndexRouting.Routing

<IndexRouter AppAssembly="@typeof(App).Assembly">
    <Found Context="routeData">
        <RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
        <FocusOnNavigate RouteData="@routeData" Selector="h1" />
    </Found>
    <NotFound>
        <PageTitle>Not found</PageTitle>
        <LayoutView Layout="@typeof(MainLayout)">
            <p role="alert">Sorry, there's nothing at this address.</p>
        </LayoutView>
    </NotFound>
</IndexRouter>

Change <NavLink> href values to use index.html?$=[PAGE_ROUTE] format in NavMenu.razor

<div class="@NavMenuCssClass nav-scrollable" @onclick="ToggleNavMenu">
    <nav class="flex-column">
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="index.html" Match="NavLinkMatch.All">
                <span class="bi bi-house-door-fill-nav-menu" aria-hidden="true"></span> Home
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="index.html?$=counter">
                <span class="bi bi-plus-square-fill-nav-menu" aria-hidden="true"></span> Counter
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="index.html?$=weather">
                <span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Weather
            </NavLink>
        </div>
        <div class="nav-item px-3">
            <NavLink class="nav-link" href="index.html?$=user/42/profile&style=dark">
                <span class="bi bi-list-nested-nav-menu" aria-hidden="true"></span> Query Param Route
            </NavLink>
        </div>
    </nav>
</div>

While NavLinks will still work without updating the href values, the 'active link' indicator they provide will not work correctly.

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.0 72 1/31/2025