Looking at the code, the issue is most likely a modification of window.location or its child properties. Any modification of these things will cause the browser to navigate to the new page, adding a new browser history entry.
Then, whenever a user tries to go back, it will rerun the code that causes the browser to nagivate to the new page, so you end up on the same page you started on. It feels like the back button was hijacked.
To fix this, usually the two ways to change the URL without changing the browser history are either using window.location.replace() which will navigate there as well, or using window.history.replaceState() which will only change the URL without naviating there.
To fix this, usually the two ways to change the URL without changing the browser history are either using window.location.replace() which will navigate there as well, or using window.history.replaceState() which will only change the URL without naviating there.