目录
-
- [一、 出现场景](#一、 出现场景)
- [二、 解决方案](#二、 解决方案)
一、 出现场景
菜单路由跳转时,有时页面会卡死,无法进行路由跳转
二、 解决方案
修改src目录下permission.js文件
js
router.onError((error) => {
const jsPattern = /Loading chunk (\S)+ failed/g
const cssPattern = /Loading CSS chunk (\S)+ failed/g
const isChunkLoadFailed = error.message.match(jsPattern || cssPattern)
const targetPath = router.history.pending.fullPath
if (isChunkLoadFailed) {
localStorage.setItem('targetPath', targetPath)
window.location.reload()
}
})
router.onReady(() => {
const targetPath = localStorage.getItem('targetPath')
const tryReload = localStorage.getItem('tryReload')
if (targetPath) {
localStorage.removeItem('targetPath')
if (!tryReload) {
router.replace(targetPath)
localStorage.setItem('tryReload', true)
} else {
localStorage.removeItem('tryReload')
}
}
})