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);