Using named attribute routes with MapSpaFallbackRoute #340

Closed
opened 2025-08-09 17:15:55 +00:00 by fergalmoran · 0 comments
Owner

Originally created by @RehanSaeed on 10/30/2017

I'd like to use attribute routing and also named routes. When I remove the default route in Startup.cs and use the [Route] and [HttpGet] attributes in my controller, the 404 page no longer gets rendered by the SPA.

[Route("")]
public class HomeController : Controller
{
    [HttpGet("", Name = HomeControllerRouteName.GetIndex)]
    public IActionResult Index() => this.View();

    [HttpGet("error", Name = HomeControllerRouteName.GetError)]
    public IActionResult Error()
    {
        this.ViewData["RequestId"] = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier;
        return this.View();
    }
}

.UseMvc(routes =>
{
    routes.MapSpaFallbackRoute(
        name: "spa-fallback",
        defaults: new { controller = "Home", action = "Index" });
})
  1. Why does the MapSpaFallbackRoute not work with attribute and named routes?
  2. How can I specify a route name instead of a controller and action name with MapSpaFallbackRoute?
*Originally created by @RehanSaeed on 10/30/2017* I'd like to use attribute routing and also named routes. When I remove the default route in `Startup.cs` and use the `[Route]` and `[HttpGet]` attributes in my controller, the 404 page no longer gets rendered by the SPA. ``` [Route("")] public class HomeController : Controller { [HttpGet("", Name = HomeControllerRouteName.GetIndex)] public IActionResult Index() => this.View(); [HttpGet("error", Name = HomeControllerRouteName.GetError)] public IActionResult Error() { this.ViewData["RequestId"] = Activity.Current?.Id ?? this.HttpContext.TraceIdentifier; return this.View(); } } .UseMvc(routes => { routes.MapSpaFallbackRoute( name: "spa-fallback", defaults: new { controller = "Home", action = "Index" }); }) ``` 1. Why does the `MapSpaFallbackRoute` not work with attribute and named routes? 2. How can I specify a route name instead of a controller and action name with `MapSpaFallbackRoute`?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github/JavaScriptServices#340
No description provided.