fix: 彻底跳出无限弹窗死循环!在拦截 Chunk Error 后,增加原生 Cache API 暴力清理脏缓存逻辑,并将重载目标强制切换为首页(/?t=xxx),避开错误路由陷阱
This commit is contained in:
parent
9d1fc36d63
commit
1308bf86fd
|
|
@ -52,12 +52,21 @@ router.onError((error) => {
|
||||||
window._chunkErrorHandled = true
|
window._chunkErrorHandled = true
|
||||||
|
|
||||||
const forceReload = () => {
|
const forceReload = () => {
|
||||||
const url = new URL(window.location.href)
|
// 不再重载当前错误路径,直接跳回首页,并带上时间戳跳出 CDN 缓存
|
||||||
url.searchParams.set('t', Date.now())
|
window.location.href = window.location.origin + '/?t=' + Date.now()
|
||||||
window.location.href = url.href
|
}
|
||||||
|
|
||||||
|
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) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
const cleanAndReload = () => {
|
|
||||||
if ('serviceWorker' in navigator) {
|
if ('serviceWorker' in navigator) {
|
||||||
navigator.serviceWorker.getRegistrations().then(registrations => {
|
navigator.serviceWorker.getRegistrations().then(registrations => {
|
||||||
for (const registration of registrations) {
|
for (const registration of registrations) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue