JSFiddle - React, Tailwind, and code Playground

HTML

<div style="height:1000px;"></div>
<button id="on">On</button>
<button id="off">Off</button>

JavaScript

var lastPos = 0;

$('#on').click(function(){
    location.hash = 'blah';
});

$('#off').click(function(){
    lastPos = $(window).scrollTop();
    location.hash = '';
});

$(window).bind('hashchange',function(event){
    var hash = location.hash.replace('#','');
    if(hash == '') $(window).scrollTop(lastPos);
    alert(hash);
});