C# / ASP.NET MVC : return ReactJS SPA from controller

Viewed 51

I have a ReactJS project with a C# & ASP.NET MVC backend:

app.UseSpa(spa =>
{
    spa.Options.SourcePath = "ClientApp";

    if (env.IsDevelopment())
    {
        spa.UseReactDevelopmentServer(npmScript: "start");
    }
});

I am looking for a way to return the ReactJS SPA from a controller.

I understand that if there is no route defined on any controller, the SPA is returned by default.

I am trying to reproduce this, but from within a controller.

Basic example:

[Route("/{path}")]
public IActionResult Test(string path)
{
    if (path == "app")
    {
        return __react_spa__;
    }

    return base.Content("<html><body><div>Hello</div></body></html>", "text/html");
}
0 Answers
Related