Commit 78d96121 by 李伟康

ChunkLoadError 重新加载页面

1 parent d1ca1dc9
...@@ -26,6 +26,7 @@ function createRouter() { ...@@ -26,6 +26,7 @@ function createRouter() {
} }
// http://scrm.dev.glsx.com.cn/dj-scrm-wx-work-attachment-activity/ // http://scrm.dev.glsx.com.cn/dj-scrm-wx-work-attachment-activity/
router.beforeEach((to, from, next) => { router.beforeEach((to, from, next) => {
console.log(router.history.pending.fullPath)
/* 路由发生变化修改页面title */ /* 路由发生变化修改页面title */
if (to.meta.title) store.dispatch('setPageMeta', to.meta) if (to.meta.title) store.dispatch('setPageMeta', to.meta)
store.commit('SET_LAST_PATH', to.name) store.commit('SET_LAST_PATH', to.name)
...@@ -39,7 +40,14 @@ router.beforeEach((to, from, next) => { ...@@ -39,7 +40,14 @@ router.beforeEach((to, from, next) => {
} else store.dispatch('navigation') } else store.dispatch('navigation')
next() next()
}) })
router.onError((error) => {
const pattern = /Loading chunk chunk-(\w)+ failed/g
const isChunkLoadFailed = error.message.match(pattern)
const targetPath = router.history.pending.fullPath
if (isChunkLoadFailed) {
router.replace(targetPath)
}
})
// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465 // Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() { export function resetRouter() {
const newRouter = createRouter() const newRouter = createRouter()
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!