From 1308bf86fde69e18c1685b190e6c0353ff5d5002 Mon Sep 17 00:00:00 2001 From: tangxinyue <524779910@qq.com> Date: Fri, 24 Jul 2026 16:31:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=BD=BB=E5=BA=95=E8=B7=B3=E5=87=BA?= =?UTF-8?q?=E6=97=A0=E9=99=90=E5=BC=B9=E7=AA=97=E6=AD=BB=E5=BE=AA=E7=8E=AF?= =?UTF-8?q?=EF=BC=81=E5=9C=A8=E6=8B=A6=E6=88=AA=20Chunk=20Error=20?= =?UTF-8?q?=E5=90=8E=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8E=9F=E7=94=9F=20Cache?= =?UTF-8?q?=20API=20=E6=9A=B4=E5=8A=9B=E6=B8=85=E7=90=86=E8=84=8F=E7=BC=93?= =?UTF-8?q?=E5=AD=98=E9=80=BB=E8=BE=91=EF=BC=8C=E5=B9=B6=E5=B0=86=E9=87=8D?= =?UTF-8?q?=E8=BD=BD=E7=9B=AE=E6=A0=87=E5=BC=BA=E5=88=B6=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E4=B8=BA=E9=A6=96=E9=A1=B5(/=3Ft=3Dxxx)=EF=BC=8C=E9=81=BF?= =?UTF-8?q?=E5=BC=80=E9=94=99=E8=AF=AF=E8=B7=AF=E7=94=B1=E9=99=B7=E9=98=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/router/index.js | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) 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) {