I've done some research but couldn't find a solution.
I have a landingpage.html. I want to redirect a user to anotherpage.html when he/she presses the back button in the browser.
So I've tried this code:
let currentUrl = location.href;
history.replaceState('', '', 'anotherpage.html');
history.pushState('', '', currentUrl);
It works not quite as expected: when the back button is pressed the browser address bar displays anotherpage.html page, however no actual redirection happens.