MintPlayer.AspNetCore.SpaServices.Routing 10.2.1

dotnet add package MintPlayer.AspNetCore.SpaServices.Routing --version 10.2.1
                    
NuGet\Install-Package MintPlayer.AspNetCore.SpaServices.Routing -Version 10.2.1
                    
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="MintPlayer.AspNetCore.SpaServices.Routing" Version="10.2.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MintPlayer.AspNetCore.SpaServices.Routing" Version="10.2.1" />
                    
Directory.Packages.props
<PackageReference Include="MintPlayer.AspNetCore.SpaServices.Routing" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add MintPlayer.AspNetCore.SpaServices.Routing --version 10.2.1
                    
#r "nuget: MintPlayer.AspNetCore.SpaServices.Routing, 10.2.1"
                    
#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.
#:package MintPlayer.AspNetCore.SpaServices.Routing@10.2.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=MintPlayer.AspNetCore.SpaServices.Routing&version=10.2.1
                    
Install as a Cake Addin
#tool nuget:?package=MintPlayer.AspNetCore.SpaServices.Routing&version=10.2.1
                    
Install as a Cake Tool

MintPlayer.AspNetCore.SpaServices.Routing

NuGet Version NuGet License

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 });

License

This project is licensed under the Apache 2.0 License.

Product 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. 
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
10.2.1 85 1/19/2026
10.2.0 88 1/18/2026
10.1.0 97 1/16/2026
10.0.2 92 1/12/2026
10.0.1 203 12/20/2025
10.0.0 577 11/13/2025
10.0.0-rc.6 240 11/11/2025
10.0.0-rc.5 235 11/11/2025
10.0.0-rc.4 152 11/5/2025
10.0.0-rc.3 156 11/5/2025
10.0.0-rc.2 152 11/5/2025
10.0.0-rc.1 153 10/2/2025
9.1.0 1,585 11/22/2024
9.0.0 1,327 11/13/2024
8.3.0 1,527 6/10/2024
8.2.0 9,259 11/28/2023
8.1.0 217 11/28/2023
8.0.0 310 11/14/2023
8.0.0-rc2 114 11/13/2023
8.0.0-rc1 110 11/6/2023
7.0.3 8,107 8/9/2023
7.0.2 2,517 12/6/2022
7.0.1 470 11/15/2022
7.0.0 532 11/14/2022
7.0.0-preview.1 224 10/30/2022
6.1.7 672 8/9/2023
6.1.6 5,861 12/6/2022
6.1.5 522 11/15/2022
6.1.4 723 10/28/2022
6.1.3 7,786 8/26/2022
6.1.2 604 8/26/2022
6.1.1 3,112 7/5/2022
6.1.0 656 7/5/2022
6.0.6 640 6/23/2022
6.0.5 3,556 12/27/2021
6.0.4 2,007 12/19/2021
6.0.3 501 12/8/2021
6.0.2 484 12/6/2021
6.0.1 481 12/2/2021
6.0.0 1,332 12/2/2021
3.1.0 525 12/2/2021
1.2.0 547 10/9/2021
1.1.5 2,702 8/20/2020
1.1.4 746 5/10/2020
1.1.3 672 5/10/2020
1.1.2 671 5/8/2020
1.1.1 672 4/29/2020
1.1.0 673 4/29/2020
1.0.5 679 2/20/2020
1.0.4 681 2/20/2020
1.0.3 698 1/17/2020
1.0.2 689 1/14/2020
1.0.1 757 12/9/2019
1.0.0 811 8/27/2019

v 3.1.0
- Moved the route builder to the SpaPrerenderingService