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
<PackageReference Include="SpawnDev.BlazorJS.IndexRouting" Version="1.0.0" />
paket add SpawnDev.BlazorJS.IndexRouting --version 1.0.0
#r "nuget: SpawnDev.BlazorJS.IndexRouting, 1.0.0"
// 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
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
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>
Update NavLinks
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 | Versions 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. |
-
net6.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 6.0.25)
-
net7.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 7.0.14)
-
net8.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 8.0.1)
-
net9.0
- Microsoft.AspNetCore.Components.WebAssembly (>= 9.0.0)
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 |