vue如果是首页了 不让其后退

history.pushState(null, null, document.URL);  //首页加载时候先置空
window.addEventListener('popstate', function(e) {  //后退事件置空
if(document.URL.split('/')[document.URL.split('/').length - 1] == 'home') {
history.pushState(null, null, document.URL);
}
});
 
参考理解原理 http://www.cnblogs.com/accordion/p/5699372.html
 
 
// 解决详情页后退到订单页面 或者订单页后退到我的页面
var that = this
history.pushState(null, null, document.URL);
window.addEventListener('popstate', function(e) {
// alert(location.protocol+'//'+location.host + '/user-center')
that.$router.replace({path: '/order/all'})
history.pushState(null, null, location.protocol+'//'+location.host + '/order/all');
});
posted @ 2018-11-24 11:40  suanmei  阅读(1097)  评论(0编辑  收藏  举报