I am facing a number of troubles related to AngularJs routing. I have already tried to find answers online but I still am not very clear with the solutions provided.
First of all, here is my routing block:
var myApp = angular.module('myApp', ["ngRoute", "ngAnimate"]);
myApp.config(function($routeProvider, $locationProvider) {
$locationProvider.html5Mode(true);
$routeProvider
.when("/", {
templateUrl: "../view/home.html",
controller: "slideShowController",
})
.when("/business&consumer", {
templateUrl: "../view/govnservices.html",
controller: "productController",
})
.when("/about", {
templateUrl: "../view/about.html",
controller: "pagController",
})
.when("/project", {
templateUrl: "../view/projects.html",
controller: "projController",
})
.when("/service", {
templateUrl: "../view/services.html",
controller: "servController",
})
.otherwise({
redirectTo: '/',
})
});
And this is how I am passing the reference to my links:
<a href="/">Home</a>
Another link:
name: "About Us",
templateUrl: "/about",
Now everywhere it is specified as:
<a href="#/">Home</a>
But on using '#' my links are not working (still don't know why.)
Again on not using '#' all my links are working but if I try to reload my page then it gives a 404 error:page not found.
Someone please help me out with this and please mention in comment if any part is not clear. Also please mention any good source to learn routing.
$locationProvider.html5Mode(true);, which removes hash-bangs -#from your URL. Using<a href="#/">Home</a>will go to an unknown location, so it will redirect you to whatever.otherwiseis pointing to. I suggest removinghtml5Mode, it's not very beginner friendly#anywhere with your links. To fix the issue with the reloading, where it goes to 404 page, you need to fix the routing manually. Because#was helping you with that, but now it's gone. Here is a solution if you have.htaccessfile on your server