I want to disable browser back button on specific condition, after implementing several snippetslike History
,popstate
etc
scenario 1: its making the code not able to use back button for anything disregarding the condition.
scenario 2: once you click back button twice its going back to browsers home page not able to know whats happening
window.addEventListener("popstate", (e) => { const es = 'D' if (es == "D") { e.preventDefault(); var currentLocation = window.location.pathname; window.history.pushState( {},"", `${currentLocation}/index/watchlist/home` ); } else {
Need: Need to disable the back button conditionally but if the condition is false it should work