feat: add del worker cache

master
guofei 2024-06-19 17:43:56 +08:00
parent fc52444bd4
commit 93242679a3
1 changed files with 24 additions and 0 deletions

View File

@ -4,6 +4,30 @@ import './styles/global.less';
import './styles/tailwind.css'; import './styles/tailwind.css';
import { routes as appRouters, loopMenuItem, type MenuItem } from './utils/router'; 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) { export function patchClientRoutes({ routes }: any) {
const routerIndex = routes.findIndex((item: MenuItem) => item.path === '/'); const routerIndex = routes.findIndex((item: MenuItem) => item.path === '/');
const routers = loopMenuItem(appRouters); const routers = loopMenuItem(appRouters);