17

Does anyone know why version 1.1.5 automatically adds a hashtag to your urls, and how to turn this off? IMO this is ugly looking. It happens whenever you have a url that doesn't end in a forward slash. (I'm not using routes or anything like that).

So this:

http://my.website.com/about

becomes

http://my.website.com/about#/about

and this:

http://my.website.com/about.html

becomes:

http://my.website.com/about.html#/about.html

but this:

http://my.website.com/about/

doesn't have this problem.

Kevin Beal
  • 10,500
  • 12
  • 66
  • 92
  • how are you setting the location? It appears as though you are using $location.path('about.html'); – Brian Lewis Jun 27 '13 at 18:52
  • @moderndegree I'm not using routes of any kind. I'm not using $locaton. It's not an app, just angular controllers in a standard web page. The path is set using actual anchors and full page loads. – Kevin Beal Jun 27 '13 at 19:29
  • 3
    I am also seeing this problem: none of my code is setting $location (I have breakpoints everywhere I touch it and they are not hitting), and problem does not occur with angular 1.1.4, so this seems to be something the framework is doing – jssebastian Jun 27 '13 at 19:32

3 Answers3

25

I experienced this issue just the other day. I solved it by enabling HTML5 mode for $locationProvider. See Docs for $location - HTML5 Mode Updated link for $location - HTML5 Mode.

It should look similar to this:

.config(['$locationProvider', function($locationProvider){
    $locationProvider.html5Mode(true).hashPrefix('!');
}]);
EnigmaRM
  • 7,523
  • 11
  • 46
  • 72
  • 4
    You saved my life. They were going to take my thumbs! – Kevin Beal Aug 21 '13 at 19:16
  • 2
    Haha. Well I'm glad that you can keep your thumbs for another day. Makes it easier to push the spacebar. Altho, my left thumb is pretty much useless when typing. So let them take that thumb if they demand one in the future :) – EnigmaRM Aug 21 '13 at 19:28
  • 4
    This does introduce a new problem though, which is that regular anchors going to another page get turned into history pushed links and the page goes nowhere. This however can be solved by making your links `target="_self"`. Doing something like `$('[href]').attr('target', '_self')` fixes that problem. If you could add something about that to your answer I will be your best friend. – Kevin Beal Aug 23 '13 at 17:26
  • That's odd. Switching to HTML5 mode did not introduce that problem for me. My links still work. Without seeing more code I'm not sure what the difference would be. Maybe it has to do with setting a base_url in your ``? – EnigmaRM Aug 26 '13 at 14:26
  • @abden003 I did a google search and updated the Docs link for you – EnigmaRM Sep 19 '15 at 04:17
  • Man, ok this fixed the hashing problem, but caused all the site to freeze anchors and links, like it was not clicked ! – Mohamad Al Asmar Oct 13 '16 at 14:09
3

This seems to be a bug introduced in angularjs 1.1.5 (since 1.1.4 does not exhibit this problem). I have reported the bug here:

https://github.com/angular/angular.js/issues/3083

jssebastian
  • 1,189
  • 1
  • 11
  • 12
1

In $routeProvider set HTML5 mode as true as following

$locationProvider.html5Mode(true);

And in head section of your page add this following line

<base href="/">
vijay
  • 93
  • 1
  • 2
  • 15