Vue路由——ie上地址栏输入路由页面不更新

2018-08-30  本文已影响368人  5df463a52098

情景:在ie11上从当前A页面(/a)跳转B页面(/b),在地址栏直接修改路由回车跳转B页面,发现页面还是A页面,但是地址栏地址已经是B页面地址。而且控制台并无报错。
解决方法:在App.vue中添加判断ie加手动修复:

mounted () {
            if (!!window.ActiveXObject || 'ActiveXObject' in window) {
                window.addEventListener('hashchange', () => {
                    let currentPath = window.location.hash.slice(1)
                    if (this.$route.path !== currentPath) {
                        this.$router.push(currentPath)
                    }
                }, false)
            }
        }

onhashchange事件ie8就已经支持了。

上一篇 下一篇

猜你喜欢

热点阅读