MvcReact 1.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package MvcReact --version 1.0.1
NuGet\Install-Package MvcReact -Version 1.0.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="MvcReact" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MvcReact --version 1.0.1
#r "nuget: MvcReact, 1.0.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.
// Install MvcReact as a Cake Addin
#addin nuget:?package=MvcReact&version=1.0.1

// Install MvcReact as a Cake Tool
#tool nuget:?package=MvcReact&version=1.0.1

Build Status Build Status NuGet version (MvcReact)

MvcReact

Library to simplify setup of AspNetCore app that serves both Mvc and React pages

Installation

dotnet add package MvcReact

Usage

Add a using statement in your app initialization code (usually Program.cs or Startup.cs)

using MvcReact;

Initialize services

services.AddMvcReact();

Or for explicit control over settings...

services.AddMvcReact(options =>
{
    options.SourcePath = "ClientApp";
    options.BuildPath = "ClientApp/build";
    options.IndexHtmlPath = "ClientApp/build/index.html";
    options.StaticAssetBasePath = "/static";
    options.StaticAssetHeaderCacheMaxAgeDays = 365;
    options.DevServerBundlePath = "/static/js/bundle.js";
    options.DevServerStartScript = "start";
    options.TagHelperCacheMinutes = 30;
    options.ExcludeHmrPathsRegex = "^(?!ws|.*?hot-update.js(on)?).*$";
});

UseMvcReactStaticFiles and UseMvcReact are the important extension methods here, along with MvcReactOptions.ExcludeHmrPathsRegex for letting hmr requests fall through

public void Configure(IApplicationBuilder app, IWebHostEnvironment env, IOptions<MvcReactOptions> mvcReactOptions)
{
    app.UseStaticFiles();
    app.UseMvcReactStaticFiles();
    app.UseRouting();

    app.UseEndpoints(routes =>
    {
        if (env.IsDevelopment())
        {
            routes.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}",
                constraints: new { controller = mvcReactOptions.Value.ExcludeHmrPathsRegex });
        }
        else
        {
            routes.MapControllerRoute(
                name: "default",
                pattern: "{controller=Home}/{action=Index}/{id?}");
        }
    });

    app.UseMvcReact();
}

Import tag helpers in _ViewImports.cshtml

@using MvcReact 
@addTagHelper *, MvcReact
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Use <react-scripts /> and <react-styles /> tag helpers to embed relavent tags in a page/view

@model SomeModel


@{
    ViewData["Title"] = "Page title";
}

<div id="react-app"></div>

@section Styles
{
    <react-styles />
}

@section Scripts
{
    <react-scripts />
}
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 was computed.  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 was computed.  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. 
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
2.0.6 126 1/12/2024
1.0.1 1,755 5/25/2023