gpt4 book ai didi

javascript - vue-router:使用浏览器后退按钮时跳过页面

转载 作者:行者123 更新时间:2023-11-30 15:21:23 31 4
gpt4 key购买 nike

我的应用程序中有一个“主页”页面和一个“成功”页面。

“成功”页面有一个按钮,单击该按钮后,通过 window.location.href='https://google 转到类似 https://google.com 的 URL .com'.

我可以从首页开始,使用vue-router推送到Success页面,然后点击按钮跳转到url。但是,当我按下浏览器的后退按钮时,我希望它返回主页而不是成功页面。

我该怎么做?

最佳答案

假设您的 javascript 在 Vue 实例中,您可以在设置 window.location.href 之前添加对 $router.replace 的调用。

它看起来像这样:

methods: {
onLinkClick() {
this.$router.replace({ name: 'home' }); // or whatever your home page name is
window.location.href='https://google.com';
}
}

这是 vue-router programmatic navigation 的文档.

关于javascript - vue-router:使用浏览器后退按钮时跳过页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43683412/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com