How can I get rid of the hash tag in my AngularJS site URL?
Asked Answered
C

1

1

I uploaded an AngularJS site to my gh-pages branch and pointed the DNS A records to 204.232.175.78. Now the site is live but I see a hash tag as part of the URL structure. Here are the two URLs one can see the home page of the site at

http://www.maxmythic.com/#/

http://siddhion.github.io/maxmythic_angular/#/

The URL I want visitors to enter and see in the address bar is simple maxmythic.com. If one enters maxmythic.com it redirects to http://www.maxmythic.com/#/.

How would I make the URL of the home page just maxmythic.com with out the www. and trailing /#/

Clear answered 27/7, 2013 at 1:12 Comment(0)
V
6

In the app's main module's config function, use the html5mode() function of the $locationProvider. Read these docs for more info: http://docs.angularjs.org/api/ng.$locationProvider and http://docs.angularjs.org/guide/dev_guide.services.$location.

Example:

angular.module('myApp', []).
  config(function($locationProvider) {
    $locationProvider.html5Mode(true);
  });
Venomous answered 27/7, 2013 at 1:34 Comment(4)
Hmm. Whenever I press refresh on any page on my site that is not maxmythic.com I get the Angular 404.html page. Also, say I have clicked around on my site 5 times, press refresh, get the 404 page and then press back to get to the last working page, well, clicking back through my history still results in the 404.html page unless I get back to my root URL maxmythic.com. Why is this happening? Should this be a new question?Clear
Can you make a new question with the route setup (the $routeProvider in the app's config()) that you are using and link back to it here? I'm not sure if that's the problem but it might help. Also, please post anything else that might aid us in finding a solution...Venomous
UPDATE: I found another StackOverflow question here that might help.Venomous
Here is my new question with as much info I have on this issue #17913043 Thanks in advance :)Clear

© 2022 - 2024 — McMap. All rights reserved.