I want to serve my AngularJS SPA from "/" and for that reason I have disabled default route and am using
// this action does not 'fire' due to Angular's routing...
routes.MapRoute(
name: "Test",
url: "Test",
defaults: new { controller = "Home", action = "Test" },
namespaces: new[] { "My.WebApp.Controllers" }
);
// Index view has no layout and contains Angular SPA
routes.MapRoute(
name: "AngularJs-SPA",
url: "{*catchall}",
defaults: new { controller = "Home", action = "Index" },
namespaces: new[] { "My.WebApp.Controllers" }
);
I am also using following angular app config block
.config(['$routeProvider', '$httpProvider', '$locationProvider', function ($routeProvider, $httpProvider, $locationProvider) {
$routeProvider.otherwise({ redirectTo: '/404' });
$httpProvider.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
$locationProvider.html5Mode(true);
}])
My question is can I still somehow have a regular server side page that responds to MVC action (in this case /Home/Test)? The issue I am seeing is that Angular takes over the routing and even if I define additional route (either before or after the angular route), Angular sees it as "otherwise" route...
Few (undesirable) solutions
- specify each angular app routes in MVC instead of {*catchall}
- move angular spa to a non root action (e.g. /app)