Fix the page jumping issue when linking to same page anchor with Turbolinks
Thomas Mak wrote at 2019-07-22.
<script>
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()
}
})
</script>
From domchristie.
Comments
no comments yet.