Created
August 7, 2018 13:45
-
-
Save jhauge/1968d69f6b622bab623a2f55e91baf2b to your computer and use it in GitHub Desktop.
ASP.NET App routing for SPA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Security.Claims; | |
using System.Web.Mvc; | |
namespace ISS.OPF.API.Controllers | |
{ | |
// [Authorize] - you don't need authorization if all page auth is handled in frontend | |
public class HomeController : Controller | |
{ | |
{ | |
return new FilePathResult("~/index.html", "text/html"); // Point to the root file of the spa | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Web.Mvc; | |
using System.Web.Routing; | |
namespace Routing.App | |
{ | |
public class RouteConfig | |
{ | |
public static void RegisterRoutes(RouteCollection routes) | |
{ | |
// You can add routes for specific controllers if you need them | |
routes.MapRoute( | |
name: "Account", | |
url: "account/{action}/{id}", | |
defaults: new { controller = "Account", action = "Index", id = UrlParameter.Optional } | |
); | |
// Catchall route - 404s will be handled in frontend app | |
// This will make the app return the result from | |
// Homecontrollers Index method on all routes not specified above | |
routes.MapRoute( | |
"Default", | |
"{*catchall}", | |
new { controller = "Home", action = "Index" } | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment