原因
主要是由于瀏覽器history記錄了iframe嵌入頁面的路由信息,這個(gè)信息不論是iframe內(nèi)的地址跳轉(zhuǎn),還是iframe src的切換,都會(huì)被記錄,下面給出解決方案
如不涉及iframe內(nèi)地址的跳轉(zhuǎn)
<iframe ref="iframeWin" width="100%" height="100%" frameborder="0"></iframe>
setIframe(src) {
this.$refs.iframeWin.contentWindow.location.replace(src);
},
原理就是讓iframe這個(gè)頁面只被記錄一次,從而實(shí)現(xiàn)“this.$router.go(-1)”正常跳轉(zhuǎn)
如涉及iframe內(nèi)地址的跳轉(zhuǎn)
首先進(jìn)入頁面,記錄history length
created() {
this.historyLength = window.history.length;
}
然后在頁面返回時(shí)獲取當(dāng)前history length,相減即可得知需要返回多少個(gè)頁面
backClick() {
let nowhl = window.history.length;
let backCount = nowhl - this.historyLength + 1;
this.$router.go(-backCount);
}
問題解決了,記錄分享一下