MintPlayer.AspNetCore.SpaServices.Routing
10.0.2
dotnet add package MintPlayer.AspNetCore.SpaServices.Routing --version 10.0.2
NuGet\Install-Package MintPlayer.AspNetCore.SpaServices.Routing -Version 10.0.2
<PackageReference Include="MintPlayer.AspNetCore.SpaServices.Routing" Version="10.0.2" />
<PackageVersion Include="MintPlayer.AspNetCore.SpaServices.Routing" Version="10.0.2" />
<PackageReference Include="MintPlayer.AspNetCore.SpaServices.Routing" />
paket add MintPlayer.AspNetCore.SpaServices.Routing --version 10.0.2
#r "nuget: MintPlayer.AspNetCore.SpaServices.Routing, 10.0.2"
#:package MintPlayer.AspNetCore.SpaServices.Routing@10.0.2
#addin nuget:?package=MintPlayer.AspNetCore.SpaServices.Routing&version=10.0.2
#tool nuget:?package=MintPlayer.AspNetCore.SpaServices.Routing&version=10.0.2
MintPlayer.AspNetCore.SpaServices.Routing
This package simplifies SPA prerendering by allowing you to define your SPA routes in ASP.NET Core and determine which route is activated in the SupplyData callback.
Installation
NuGet Package Manager
Install-Package MintPlayer.AspNetCore.SpaServices.Routing
.NET CLI
dotnet add package MintPlayer.AspNetCore.SpaServices.Routing
MSBuild Integration
This package includes MintPlayer.AspNetCore.NodeServices which automatically configures your project with build targets for SPA development.
Properties
| Property | Default | Description |
|---|---|---|
EnableSpaBuilder |
true |
Master switch to disable SPA build automation |
SpaRoot |
ClientApp\ |
Path to your SPA source folder |
BuildServerSideRenderer |
true |
Whether to build the SSR bundle |
Disabling SPA Builder
If your project doesn't have a SPA but references this package:
<PropertyGroup>
<EnableSpaBuilder>false</EnableSpaBuilder>
</PropertyGroup>
Usage
1. Register SPA Routes
Define your SPA routes in ConfigureServices:
public void ConfigureServices(IServiceCollection services)
{
services.AddSpaRoutes(routes => routes
.Route("", "home")
.Group("person", "person", person_routes => person_routes
.Route("", "list")
.Route("create", "create")
.Route("{id}", "show")
.Route("{id}/edit", "edit")
)
);
}
2. Supply Data Based on Route
Use ISpaRouteService to determine the current route and supply appropriate data:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISpaRouteService spaRouteService)
{
app.UseSpa(spa =>
{
spa.UseSpaPrerendering(options =>
{
options.SupplyData = (context, data) =>
{
var route = spaRouteService.GetCurrentRoute(context);
var personRepository = context.RequestServices.GetRequiredService<IPersonRepository>();
switch (route?.Name)
{
case "person-list":
data["people"] = personRepository.GetPeople();
break;
case "person-show":
case "person-edit":
var id = Convert.ToInt32(route.Parameters["id"]);
data["person"] = personRepository.GetPerson(id);
break;
}
};
});
});
}
3. Use Data in Angular (main.server.ts)
const providers: StaticProvider[] = [
{ provide: APP_BASE_HREF, useValue: params.baseUrl },
{ provide: 'BASE_URL', useValue: params.origin + params.baseUrl },
];
if ('people' in params.data) {
providers.push({ provide: 'PEOPLE', useValue: params.data.people });
}
if ('person' in params.data) {
providers.push({ provide: 'PERSON', useValue: params.data.person });
}
4. Generate URLs Server-Side
Generate SPA URLs from C# code (useful for redirects, sitemaps, etc.):
// Using a dictionary
var parms = new Dictionary<string, object> { ["id"] = 5 };
var url = spaRouteService.GenerateUrl("person-edit", parms);
// Using an anonymous type
var url = spaRouteService.GenerateUrl("person-edit", new { id = 5 });
Related Packages
- MintPlayer.AspNetCore.NodeServices - Node.js integration
- MintPlayer.AspNetCore.SpaServices - Core SPA services
- MintPlayer.AspNetCore.SpaServices.Prerendering - Prerendering support
License
This project is licensed under the Apache 2.0 License.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- MintPlayer.AspNetCore.SpaServices.Prerendering (>= 10.0.2)
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 |
|---|---|---|
| 10.0.2 | 84 | 1/12/2026 |
| 10.0.1 | 193 | 12/20/2025 |
| 10.0.0 | 458 | 11/13/2025 |
| 10.0.0-rc.6 | 236 | 11/11/2025 |
| 10.0.0-rc.5 | 232 | 11/11/2025 |
| 10.0.0-rc.4 | 148 | 11/5/2025 |
| 10.0.0-rc.3 | 151 | 11/5/2025 |
| 10.0.0-rc.2 | 148 | 11/5/2025 |
| 10.0.0-rc.1 | 147 | 10/2/2025 |
| 9.1.0 | 1,583 | 11/22/2024 |
| 9.0.0 | 1,323 | 11/13/2024 |
| 8.3.0 | 1,499 | 6/10/2024 |
| 8.2.0 | 9,136 | 11/28/2023 |
| 8.1.0 | 214 | 11/28/2023 |
| 8.0.0 | 305 | 11/14/2023 |
| 8.0.0-rc2 | 113 | 11/13/2023 |
| 8.0.0-rc1 | 109 | 11/6/2023 |
| 7.0.3 | 7,728 | 8/9/2023 |
| 7.0.2 | 2,485 | 12/6/2022 |
| 7.0.1 | 470 | 11/15/2022 |
| 7.0.0 | 528 | 11/14/2022 |
| 7.0.0-preview.1 | 223 | 10/30/2022 |
| 6.1.7 | 669 | 8/9/2023 |
| 6.1.6 | 5,860 | 12/6/2022 |
| 6.1.5 | 522 | 11/15/2022 |
| 6.1.4 | 722 | 10/28/2022 |
| 6.1.3 | 7,776 | 8/26/2022 |
| 6.1.2 | 603 | 8/26/2022 |
| 6.1.1 | 3,106 | 7/5/2022 |
| 6.1.0 | 653 | 7/5/2022 |
| 6.0.6 | 635 | 6/23/2022 |
| 6.0.5 | 3,551 | 12/27/2021 |
| 6.0.4 | 2,005 | 12/19/2021 |
| 6.0.3 | 500 | 12/8/2021 |
| 6.0.2 | 483 | 12/6/2021 |
| 6.0.1 | 479 | 12/2/2021 |
| 6.0.0 | 1,328 | 12/2/2021 |
| 3.1.0 | 524 | 12/2/2021 |
| 1.2.0 | 543 | 10/9/2021 |
| 1.1.5 | 2,700 | 8/20/2020 |
| 1.1.4 | 739 | 5/10/2020 |
| 1.1.3 | 671 | 5/10/2020 |
| 1.1.2 | 668 | 5/8/2020 |
| 1.1.1 | 671 | 4/29/2020 |
| 1.1.0 | 671 | 4/29/2020 |
| 1.0.5 | 678 | 2/20/2020 |
| 1.0.4 | 676 | 2/20/2020 |
| 1.0.3 | 694 | 1/17/2020 |
| 1.0.2 | 687 | 1/14/2020 |
| 1.0.1 | 754 | 12/9/2019 |
| 1.0.0 | 808 | 8/27/2019 |
v 3.1.0
- Moved the route builder to the SpaPrerenderingService