Skip to content

Instantly share code, notes, and snippets.

@jhauge
Created August 7, 2018 13:45
Show Gist options
  • Save jhauge/1968d69f6b622bab623a2f55e91baf2b to your computer and use it in GitHub Desktop.
Save jhauge/1968d69f6b622bab623a2f55e91baf2b to your computer and use it in GitHub Desktop.
ASP.NET App routing for SPA
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
}
}
}
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