34 lines
946 B
TypeScript
34 lines
946 B
TypeScript
"use client";
|
|
|
|
import { useEffect } from 'react';
|
|
|
|
interface DynamicFaviconProps {
|
|
logoUrl?: string;
|
|
}
|
|
|
|
export default function DynamicFavicon({ logoUrl }: DynamicFaviconProps) {
|
|
useEffect(() => {
|
|
if (!logoUrl) return;
|
|
|
|
// Remove favicons antigos
|
|
const existingLinks = document.querySelectorAll("link[rel*='icon']");
|
|
existingLinks.forEach(link => link.remove());
|
|
|
|
// Adiciona novo favicon
|
|
const link = document.createElement('link');
|
|
link.type = 'image/x-icon';
|
|
link.rel = 'shortcut icon';
|
|
link.href = logoUrl;
|
|
document.getElementsByTagName('head')[0].appendChild(link);
|
|
|
|
// Adiciona Apple touch icon
|
|
const appleLink = document.createElement('link');
|
|
appleLink.rel = 'apple-touch-icon';
|
|
appleLink.href = logoUrl;
|
|
document.getElementsByTagName('head')[0].appendChild(appleLink);
|
|
|
|
}, [logoUrl]);
|
|
|
|
return null;
|
|
}
|