I have html5mode enabled in my AngularJS application so I can access paths with the URL format site.com/path
instead of site.com/#/path
.
But navigation to a hash is not working properly with html5mode enabled. When I navigate to site.com/#hash
through Chrome, the URL automatically changes to site.com/hash
. Since hash
is not a resource on the server, this URL results in the loading of the default index.html file instead of scrolling to the hash
location.
This seems to be a very trivial use case but how can I make the URL format site.com/#hash
work as expected with AngularJS?
I got it to work with the help of:
Quoting from the docs page:
Note that removing the requirement for a tag will have adverse side effects when resolving relative paths with $location in IE9.
To summarize, Angular leaves hash-fragments in the URL untouched only if:
requireBase:false
while enabling html5modeNo wonder people find it difficult to grasp AngularJS: the documentation is weak and the framework is like a magic black-box that takes control of your app away from you.