ReactJS .Net CORE
Can we have a similar repo for ReactJS for .Net Core please? Will be great for dummies like myself.
hi @fhlee74
CoreUI is a standard CRA React app. Therefore basic setup of CoreUI for .NET Core 2.1 using .Net Core 2.1 React project template should be straightforward.
1. Prerequisites:
-
.NET Core 2.1.2withSDK 2.1.302installed - SDK Installer -
Node.js, version8.11or later - code editor of your choice (if you prefer
Visual Studioyou need to use version2017 15.7.xor newer)
2. Create a new app
- in an empty directory create a new project from a command prompt
dotnet new react - remove sample application directory
rd ClientApp /S /Q - clone CoreUI repo:
git clone https://github.com/coreui/coreui-free-react-admin-template CoreUI - edit
react.csprojand modify<SpaRoot>ClientApp\</SpaRoot>to<SpaRoot>CoreUI\</SpaRoot> - edit
startup.csand modify:
configuration.RootPath = "ClientApp/build";toconfiguration.RootPath = "CoreUI/build";
andspa.Options.SourcePath = "ClientApp";tospa.Options.SourcePath = "CoreUI";
3. Build and run
- from
Visual Studioopen the.csprojfile, and run the app (the build process restoresnpm dependencieson the first run) - or from
.NET Core CLI- Run
dotnet build - Run
dotnet runto start the app
- Run
See also: https://docs.microsoft.com/en-us/aspnet/core/client-side/spa/react?view=aspnetcore-2.1&tabs=netcore-cli
@xidedix with that type of setup for the startup.cs SourcePath and RootPath, I'm randomly getting the following error on my dev server: "Exception":"System.InvalidOperationException: The SPA default page middleware could not return the default page '/index.html' because it was not found, and no other middleware handled the request.\nYour application is running in Production mode, so make sure it has been published, or that you have built your SPA manually. Alternatively you may wish to switch to the Development environment.
Any ideas? Everything I am finding is saying it's because the RootPath and SourcePath can't find the page, but most of the time it works.