feat: implement PWA, manifest, service worker and offline indicator
This commit is contained in:
22
src/components/PWARegistration.tsx
Normal file
22
src/components/PWARegistration.tsx
Normal file
@@ -0,0 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from 'react';
|
||||
|
||||
export default function PWARegistration() {
|
||||
useEffect(() => {
|
||||
if ('serviceWorker' in navigator && window.location.hostname !== 'localhost') {
|
||||
window.addEventListener('load', () => {
|
||||
navigator.serviceWorker
|
||||
.register('/sw.js')
|
||||
.then((registration) => {
|
||||
console.log('SW registered: ', registration);
|
||||
})
|
||||
.catch((registrationError) => {
|
||||
console.log('SW registration failed: ', registrationError);
|
||||
});
|
||||
});
|
||||
}
|
||||
}, []);
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user