When I try to redirect to another page by clicking a button or a link, the URL changes but the redirection doesn't happen. I have to manually refresh the page with the new URL. I'm not sure if the issue lies in the module or the controller.
locationController.js
angular.module('reservationModule').controller('locationController', function($scope, $location){
$scope.setLocation = function (url) {
$location.path(url);
};
})
reservationModule.js
(function () {
var resModule = angular.module('reservationModule', ['ngRoute']);
resModule.controller('HomeController', function ($scope) {
$scope.Message = "Success! First part done.";
});
resModule.config(function ($locationProvider, $routeProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when('/', {
templateUrl: '/Home/Index.cshtml',
controller: 'locationController'
})
.when('/Home/Index', {
templateUrl: '/Home/Index.cshtml',
controller: 'locationController'
})
// More routes defined here
.otherwise({ redirectTo: '/' });
});
})();
Index.cshtml
@{
// Layout = "~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "Web Reservation System";
}
<base href="/">
<div class="container" ng-controller="locationController">
<header class="header">
<div class="headerleft">
<div class="headerlogo">
<a href="/Home/Index"><img alt="reservation" src="../Content/pics/vetstoria-logo.jpg" width="50" height="50"></a>
</div>
</div>
<div class="headerright">
<p class="headerlogintext">
<a class="btn headerlogin" href="/Home/Login" style="text-decoration:none">Login</a>
</p>
</div>
</header>
<div class="content">
<h1 class="content-title">Web Reservation System</h1>
<p class="content-title-text">In our reservation system, you can book anything you want. Whether it's a sports facility, a course, or something else, it's easy with us.</p>
<p class="content-title-text">Just one thing to get started.</p>
<button class="btn-big" ng-click="setLocation('/Home/Registration')">Register</button>
</div>
@section Scripts{
<script src="~/Scripts/Angular_Controllers/locationController.js"></script>
}
I've tried troubleshooting this issue by researching online forums, but I still haven't been able to determine where the problem lies exactly within the code.