使用 pushstate / popstate 的重定向问题 - javascript

Redirection issue using push state / pop state - with javascript

我的网站有以下场景。当用户在支付(结帐)页面并点击后退按钮时,默认显示错误页面。

我希望我的用户在主页上被重定向!

我试过以下代码:

function extractDomain(url) {
    var domain;
    if (url.indexOf("://") > -1) {
      domain = url.split('/')[2];
    }
    else {
            domain = url.split('/')[0];
    }
    domain = domain.split(':')[0];

    return domain;
}

var url = extractDomain(window.location.href);

if(jQuery("#checkout_page".length=1)){
    history.pushState(null, null, url);

    window.addEventListener("popstate", function(e) {
       window.location.assign("http://"+url)
   });
}

以上代码存在以下问题:

当用户在结帐页面上时,域会附加到用户(由于推送状态)。

有什么办法,我可以保持准确的 behavior/redirection,但不必在 url 的末尾附加域?

此外,这是我实现重定向的合法方法吗/有没有更好的方法来做到这一点?

任何帮助将不胜感激

此致...

设法让它工作:)

我只需要推当前 url..

line => history.pushState(null, null, url);
change to => history.pushState(null, null, window.location.href);