diff --git a/src/router/index.js b/src/router/index.js index 7b1f8b5..8f208c3 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -52,12 +52,21 @@ router.onError((error) => { window._chunkErrorHandled = true const forceReload = () => { - const url = new URL(window.location.href) - url.searchParams.set('t', Date.now()) - window.location.href = url.href + // 不再重载当前错误路径,直接跳回首页,并带上时间戳跳出 CDN 缓存 + window.location.href = window.location.origin + '/?t=' + Date.now() } - const cleanAndReload = () => { + const cleanAndReload = async () => { + // 暴力清空所有的 Cache API,防止 SW 缓存 index.html 等 + if (window.caches) { + try { + const keys = await window.caches.keys() + for (const key of keys) { + await window.caches.delete(key) + } + } catch (e) {} + } + if ('serviceWorker' in navigator) { navigator.serviceWorker.getRegistrations().then(registrations => { for (const registration of registrations) {