Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove index.html from url on website based on angularjs

I didn't find a way to remove index.html from the url, because like this looks really ugly.

mydomain.com/index.html#/myview1 
mydomain.com/index.html#/myview2

Is there a way to remove that part, like that url will be so clear where the user is.

mydomain.com/myview1
mydomain.com/myview2

Tnx in advance for your time.

Edit: I just find way that it could work like:

mydomain.com/#/myview1
mydomain.com/#/myview2

which is pretty much better then with index.html.

But still if there is a way for shorter solution let me know.

like image 539
Pnctovski Avatar asked Jul 17 '13 12:07

Pnctovski


2 Answers

Maybe this approach could help:

Add $locationProvider.hashPrefix();, which removes index.html in your URL, in your app.js config. Don't forget to add the new dependency. After that your app.js could look similar to this:

 angular.module('myApp', [
  'ngRoute'
]).
config(['$locationProvider', '$routeProvider', function($locationProvider, $routeProvider) {
  $locationProvider.hashPrefix(); // Removes index.html in URL

  $routeProvider.otherwise({redirectTo: '/someroute'});
}]);

Note that this does not remove the hashtag. You can find your new route at: .../app/#/someroute

like image 53
Robin Wieruch Avatar answered Oct 21 '22 16:10

Robin Wieruch


activate the html5mode for $location

like image 31
Eduard Gamonal Avatar answered Oct 21 '22 17:10

Eduard Gamonal