Question

I'm building an application with AngularJs and it's using Html5 routing. The issue is when you refresh the page the route isn't valid. Now I could go through and add an entry for every route and return my main page (which is what I've done) but I was wondering if there is a singular way to always return the same page, lets say controller="Home", Action="Index", no matter what url request comes in.

Was it helpful?

Solution

public class RouteConfig
{
    public static void RegisterRoutes(RouteCollection routes)
    {
        routes.IgnoreRoute("{resource}.axd/{*pathInfo}");



        // We have an angular application. All other pages routing is done there
        // This route must be the last one!
        routes.MapRoute(
             "Default",
             "{*url}",
             new { controller = "AngularApp", action = "Layout" }
         );
    }
}

In my example, as you can see all the requests are directed to AngularAppController, Layout Action

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top