Anchor links in HTML5 mode go to 'base url' and trigger a navigation event #5519
Description
I have an app with $locationProvider.html5Mode(true)
, so no hashes in the URLs; I figured I could use anchors like they used to again, but unfortunately that doesn't seem to be the case.
I made a plunkr to try and highlight the problem:
http://plnkr.co/edit/Upc89hCMMVbAhJaV2XYd?p=preview
full-screen with visible path version: http://run.plnkr.co/IA9Gwp52MzFpE1O6/
Issue 1 is that an <a href="#anchor">
will link to http://host/#anchor
, instead of http://host/currenPath/#anchor
.
Issue 2 is that when I create an url <a href="path/#anchor">
and click it, a navigation event is triggered - highlighted in the plunkr by a page transition animation.
StackOverflow questions offer answers like this work around the limitation by calling $location.hash()
and $anchorScroll
, but those will also trigger a navigation event. The second solution there is to reset $location.hash to the old value - i.e. none - to avoid the navigation event from triggering, but that removes the option to link directly to anchors from other pages and removes bookmarkability.
I came across issue #648 which seems to outline the same issue (two years ago), but it seems it stopped working sometime since then.
tl;dr: I'd like to do <a href="#anchor">
that links to an anchor at the current route, but it links to the base URL and triggers a navigation event.