I am trying to make an application which would host two SPAs with one backend. I have followed the instructions for creating a React app with .NET Core. This worked perfectly.
Then I changed the configuration to start the .NET Core and React apps separately. Also no problem.
However, then I tried to follow the guide on hosting multiple SPAs under different subroues. And suddenly I am gettig 404s for my script:
Here is my Configure
method:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseSpaStaticFiles();
app.UseRouting();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller}/{action=Index}/{id?}");
});
app.Map("/reactapp", ra => {
ra.UseSpa(spa =>
{
spa.Options.SourcePath = "ClientApp";
if (env.IsDevelopment())
{
spa.UseProxyToSpaDevelopmentServer("http://localhost:3000");
}
});
});
}
The individual HTTP calls seem to be almost identical, except for the /reactapp
path. What am I doing wrong? Is there any additional configuration needed on .NET side? Or should I change something in the React app (e.g.: in React router)?