Search code examples
angularjsurlrouteshashbang

Why does setting the URL hash through AngularJS's $location.hash add an extra "#/" before the hash?


After adding the statement $location.hash('tab1');, I expected the URL to change to '/#tab1' but it becomes '/#/#tab1'.

What is causing the extra '#/' to appear and how can I avoid it?

UPDATE: To clarify, I do not want to remove the hash from the fragment URL but the empty path. Per my syntax $location.hash('tab1');, I expected the browser URL to become '/#tab1' but it became '/#/#tab1'.


Solution

  • The extra '#/' is caused by $locationProvider configuration. It can be removed by

    $locationProvider.html5Mode(true)

    See Removing the hashtag from AngularJS urls (# symbol)