Integrating SPA ( Angular, React, Vue) with .NET Core for production
If you have a .NET Core WebAPI application ( that only serves data ) and a SPA application ( Angular, Vue, React) you can have just one application following this 2 steps:
1. In .NET Core add in Startup.cs ( with using Microsoft.AspNetCore.Builder from Microsoft.AspNetCore.StaticFiles )
app.UseDefaultFiles();
app.UseStaticFiles();app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
// If you know the endpoints, put it here
//endpoints.MapFallbackToFile(“dbodepartment/{**slug}”,”/index.html”);
endpoints.MapControllers();
endpoints.MapFallbackToFile(“{**slug}”, “/index.html”);
});
2. Compile the SPA to index.html, deploy in wwwroot with the js and css
( yes, you should modify the endpoint for data when compiling to / – for Angular see my previous post , http://msprogrammer.serviciipeweb.ro/2020/09/14/angular-base-href-for-web-desktop-mobile-and-paths-for-services/ )
Leave a Reply