I am trying to remove the hashtags from my Angularjs app's URLs using the locationProvider, and it works well until I refresh a page manually. This always causes a "cannot GET .." error in the browser. I have done some research and I think I have to use an .htaccess file to redirect, but I am not sure how to implement it and I have searched the web for a solution but no luck so far.
Here is my app.js which handles routing to my Angular views and controllers:
(function () {
'use strict';
var myApp = angular.module('myApp', ['ngRoute']);
myApp.config(function($routeProvider, $locationProvider) {
$routeProvider.
when('/', {
templateUrl: 'views/partials/play.html',
controller: 'playCtrl'
}).
when('/dictionary', {
templateUrl: 'views/partials/dictionary.html',
controller: 'dictionaryCtrl'
}).
when('/add', {
templateUrl: 'views/partials/word.html',
controller: 'wordCtrl'
}).
when('/about', {
templateUrl: 'views/partials/about.html',
controller: 'aboutCtrl'
}).
otherwise({redirectTo: '/'});
// use the HTML5 History API
$locationProvider.html5Mode(true);
});
})();
And I have also added this inside the <head> in my index.html:
<base href="/">
The app is built using Node.js, Express, Angular & Mongodb if this helps.
Many thanks.