JSFiddle - React, Tailwind, and code Playground

HTML

<a href="" id="link">test</a>

JavaScript

document.getElementById("link").onclick = function() {
    history.pushState({page: 123}, "title 1", "/test");
    this.innerHTML = "Now click the back button";
    return false;
};

window.onpopstate = function(e) {
    alert("Current location: " + location.href);
    
    var data = e.state;
    if(data) {
        alert(JSON.stringify(e.state));
    }
};