From 93242679a33030f29f6092d31d781417a33ce7bb Mon Sep 17 00:00:00 2001 From: guofei Date: Wed, 19 Jun 2024 17:43:56 +0800 Subject: [PATCH] feat: add del worker cache --- src/app.tsx | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/app.tsx b/src/app.tsx index 570cf94..81d015a 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -4,6 +4,30 @@ import './styles/global.less'; import './styles/tailwind.css'; import { routes as appRouters, loopMenuItem, type MenuItem } from './utils/router'; +if ('serviceWorker' in navigator) { + window.addEventListener('load', () => { + // 获取所有注册的 Service Worker + navigator.serviceWorker + .getRegistrations() + .then((registrations) => { + for (let registration of registrations) { + // 注销每个 Service Worker + registration + .unregister() + .then(() => { + console.log('Service Worker unregistered'); + }) + .catch((error) => { + console.error('Service Worker unregistration failed:', error); + }); + } + }) + .catch((error) => { + console.error('Error fetching service worker registrations:', error); + }); + }); +} + export function patchClientRoutes({ routes }: any) { const routerIndex = routes.findIndex((item: MenuItem) => item.path === '/'); const routers = loopMenuItem(appRouters);