diff --git a/src/router/index.js b/src/router/index.js index 88f4efa..7b1f8b5 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -48,16 +48,16 @@ router.beforeEach(async (to, from, next) => { router.onError((error) => { const pattern = /Failed to fetch dynamically imported module|Importing a module script failed/i if (pattern.test(error?.message || '')) { - const isReloaded = sessionStorage.getItem('chunk_reload_flag') - if (!isReloaded) { - sessionStorage.setItem('chunk_reload_flag', 'true') - - const forceReload = () => { - const url = new URL(window.location.href) - url.searchParams.set('t', Date.now()) - window.location.href = url.href - } + if (window._chunkErrorHandled) return + window._chunkErrorHandled = true + + const forceReload = () => { + const url = new URL(window.location.href) + url.searchParams.set('t', Date.now()) + window.location.href = url.href + } + const cleanAndReload = () => { if ('serviceWorker' in navigator) { navigator.serviceWorker.getRegistrations().then(registrations => { for (const registration of registrations) { @@ -69,6 +69,12 @@ router.onError((error) => { forceReload() } } + + if (window.confirm('系统检测到版本更新,当前页面数据已过期。点击【确定】立即刷新体验最新版本!')) { + cleanAndReload() + } else { + window._chunkErrorHandled = false + } } })