Three simple steps to enable Angular HTML5 routes in ASP.NET MVC application.

  1. Redirect all controller actions to Index action, let angular handle view loading.
    routes.MapRoute(
        name: "Default",
        url: "{controller}/{*parameters}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
    
  2. Add base element in head section:
    <base href="/">
    
  3. Enable html5 routes in angular module config function:
    $locationProvider.html5Mode(true);
    

 

Source code

Comments


Comments are closed