In ASP.NET Core 2.x I used standard routes registation Configure
method of Startup
class to register fallback route for SPA application using MapSpaFallbackRoute
extension method from Microsoft.AspNetCore.SpaServices.Extensions
Nuget package:
public void Configure(IApplicationBuilder app)
{
// ...
app.UseMvc(routes =>
{
routes.MapRoute(
name: "default",
template: "{controller=Home}/{action=Index}/{id?}");
routes.MapSpaFallbackRoute(
name: "spa-fallback",
defaults: new { controller = "Home", action = "Index" });
});
}
I cannot find similar extension method when using ASP.NET Core 3.0 recommended UseEndpoints
extension method for endpoints registration.
MapSpaFallbackRoute(IRouteBuilder, String, Object, Object, Object) Configures a route that is automatically bypassed if the requested URL appears to be for a static file (e.g., if it has a filename extension).
An Endpoint is an object that contains everything that you need to execute the incoming Request. The Endpoint object contains the following information. Metadata of the request. The delegate (Request handler) that ASP.NET core uses to process the request.
Fast: ASP.NET Core no longer depends on System. Web. dll for browser-server communication. ASP.NET Core allows us to include packages that we need for our application.
In ASP.NET Core 3.0 extension method MapFallbackToController
has same functionality to MapSpaFallbackRoute
extension method.
public void Configure(IApplicationBuilder app) { app.UseRouting(); app.UseEndpoints(endpoints => { endpoints.MapControllerRoute( name: "default", pattern: "{controller=Home}/{action=Index}/{id?}"); endpoints.MapFallbackToController("Index", "Home"); }); }
This decision helped me!
public void Configure(IApplicationBuilder application)
{
application
// other extensions...
.UseEndpoints(endpoints => endpoints.MapDefaultControllerRoute())
.UseSpa(_ => { }); // extension from 'Microsoft.AspNetCore.SpaServices.Extensions' assembly
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With