在IE11瀏覽器中,router-link的跳轉是失效的,主要是因爲當url的hash變化的時候,瀏覽器沒有做出相應的反應。這時候需要做一個兼容處理,當瀏覽器是IE11時手動給url加一個hashChange事件。
辦法一:
new Vue({
el: '#app',
router,
components: {
App
},
template: '<App/>',
render: function(createElement) {
if ('-ms-scroll-limit' in document.documentElement.style && '-ms-ime-align' in document.documentElement.style) {
window.addEventListener('hashchange', () => {
var currentPath = window.location.hash.slice(1)
if (this.$route.path !== currentPath) {
this.$router.push(currentPath)
}
}, false)
}
return createElement(App);
}
})