Is checking for the href starting with # a fully sufficient way to handle this? What about links that include a relative path, absolute path, or full URL to the same page with a fragment?
The last time I checked this, it appeared that browsers issue requests unless the href starts with #
, however, I have rerun those tests today and they don't issue requests anymore. With that in mind, we can update the workaround to:
document.addEventListener('turbolinks:click', function (event) { var anchorElement = event.target var isSamePageAnchor = ( anchorElement.hash && anchorElement.origin === window.location.origin && anchorElement.pathname === window.location.pathname )if (isSamePageAnchor) { Turbolinks.controller.pushHistoryWithLocationAndRestorationIdentifier( event.data.url, Turbolinks.uuid() ) event.preventDefault() } })
IIRC, this is the approach taken in #285
https://github.com/turbolinks/turbolinks/issues/78