1
0
mirror of https://github.com/PanJiaChen/vue-element-admin.git synced 2026-04-30 02:44:12 +08:00

Fix #439: handle chunk load failures by reloading the page

When a new version is deployed and old chunks are replaced, users
with the old HTML in-session will encounter "Loading chunk N failed"
errors on lazy-loaded routes. Add a router.onError handler to detect
these failures and reload the page so the browser fetches fresh HTML
and updated chunk manifests.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Your Name 2026-02-20 21:42:59 -08:00
parent 6858a9ad67
commit 8e7c232c0c

View File

@ -72,3 +72,11 @@ router.afterEach(() => {
// finish progress bar
NProgress.done()
})
router.onError((error) => {
const pattern = /Loading chunk (\d)+ failed/g
const isChunkLoadFailed = error.message.match(pattern)
if (isChunkLoadFailed) {
window.location.reload()
}
})