vue-router:使用浏览器后退按钮时跳过页面
vue-router: skip page when using browser back button
我的应用程序中有一个 "Home" 页面和一个 "Success" 页面。
“成功”页面有一个按钮,单击该按钮会转到 URL,例如 https://google.com
,通过 window.location.href='https://google.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';
}
}
我的应用程序中有一个 "Home" 页面和一个 "Success" 页面。
“成功”页面有一个按钮,单击该按钮会转到 URL,例如 https://google.com
,通过 window.location.href='https://google.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';
}
}