Mike Gmez Mike Gmez - 26 days ago 10
AngularJS Question

Angular MVC routing prefix

Application was working fine yesterday, but after modifying a few things here and there, all hell broke loose. My api/xxx calls and root template calls are all being prefixed with the home controller:

/Home/api/admin/group/getGroups
/Home/api/admin/role/getRoles
/Home/api/admin/group/getGroups

/Home/directivesHTML/userGrid.html
/Home/directivesHTML/userGrid2.html
/Home/directivesHTML/branchGrid.html
/Home/directivesHTML/feeGrid.html
/Home/directivesHTML/reportGroupGrid.html
/Home/directivesHTML/productGrid.html
/Home/directivesHTML/applicationGrid.html
/Home/Images/loading.gif


Config files seem to be fine, dont really know where the issue is. Any idea guys? (thanks.)

$routeProvider
.when('/home', { templateUrl: '/home/main', controller: 'MainController' })
.when('/accounts', { templateUrl: '/home/accounts', controller:'accountsController'})
.when('/reports', { templateUrl: '/home/reports', controller:'reportsController'})
.when('/login', { templateUrl: '/home/login', controller: 'loginController' })
.when('/SignIn', { templateUrl: '/home/SignIn', controller: 'loginController' })
.when('/logout', { templateUrl: '/home/logout', controller: 'loginController' })
.otherwise({ redirectTo: '/home' });
}])
.controller('RootController', ['$window', '$rootScope', '$scope', '$route', '$routeParams', '$location',
function ($window, $rootScope, $scope, $route, $routeParams, $location) {
$scope.$on('$routeChangeSuccess', function (e, current, previous) {
$scope.activeViewPath = $location.path();
});
}]);


-----------------------------------------------------------------------------------------
RoutConfig
----------
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.IgnoreRoute("Shared/{resource}.ashx/{*pathInfo}");

routes.MapMvcAttributeRoutes();

routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}



Answer Source

The issue seemed to be mostly related to my posting from my form's login page. For some reason, it kept the controller "Home" as part of the path from there on. I just replaced the form action, from calling a method in the mvc, to calling a web api method from angular. It works fine now.