如何导航到页面,但确保刷新目标页面

how can I navigate to page but ensure that the target page will be refreshed

本文关键字:确保 目标 刷新 何导航 导航      更新时间:2023-09-26

我有一个Login.html页面,从中导航到我的Main.html

现在当我;我正在注销,我想导航回login.html,但我也想确保这个页面会被刷新。我不想禁用页面缓存,我只想在刷新后在这个特定的场景中导航它。

我尝试了以下操作:
window.location.replace,但它不刷新页面
window.location.href-也不会刷新页面
window.location.reload()-仅刷新当前页面。

@Christof13关于传递参数的建议是我唯一能看到的方法,但它加载了两次页面,非常难看,

还有其他建议吗?

在注销事件上设置Timeout怎么样?这样,位置只会重新加载一次。

$("#myLogOutButtonOrLink").click(function() {
    setTimeout(function(){
        window.location.reload();
        }, 1000);
});

我的解决方案在窗口作用域上使用了一个全局变量,如下所示:

在main.html上:

window.globals.RefreshRequired = true

登录html:

if (window.globals && window.globals.RefreshRequired) {
            window.location.reload();
        }

通过这种方式,如果我在当前浏览器实例中已经访问了main.html,那么刷新就会完成。