Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const scrollToOrigin = () => {
const hash = window.location.hash
if (hasInHash(hash, '#/') || hasInHash(hash, '#!/')) {
// Extracts the id param of hash
const idHashParam = getParameterByName(hash, 'id')
// For default scroll scrollTop is the page top
let scrollTop = 0
if (idHashParam) {
// Searches the node with the same id, takes his offsetTop
// And with offsetTop, tries to scroll to node
const idElement = document.getElementById(idHashParam)
if (idElement && idElement.offsetTop) {
scrollTop = idElement.offsetTop
}
}
window.scrollTo(0, scrollTop)
}