const { useEffect, useState } = React; function normalizePath(pathname) { if (!pathname || pathname === "/" || pathname === "/index.html") { return "/"; } if (pathname.length > 1 && pathname.endsWith("/")) { return pathname; } if (pathname.indexOf(".") === -1) { return pathname + "/"; } return pathname; } function App() { const [scrolled, setScrolled] = useState(false); useEffect(function bindScrollListener() { const onScroll = function onScroll() { setScrolled(window.scrollY > 20); }; onScroll(); window.addEventListener("scroll", onScroll); return function cleanup() { window.removeEventListener("scroll", onScroll); }; }, []); const currentPath = normalizePath(window.location.pathname); const links = [ { label: "Inicio", href: "/" }, { label: "Sobre Nosotros", href: "/sobre-nosotros/" }, { label: "Especialidades", href: "/especialidades/" }, { label: "Contacto", href: "/contacto/" }, ]; const pageMap = { "/": { title: "Hernández & Asociados", render: function renderHome() { return ; }, }, "/sobre-nosotros/": { title: "Sobre Nosotros | Hernández & Asociados", render: function renderAbout() { return ; }, }, "/especialidades/": { title: "Especialidades | Hernández & Asociados", render: function renderSpecialties() { return ; }, }, "/contacto/": { title: "Contacto | Hernández & Asociados", render: function renderContact() { return ; }, }, }; const activePage = pageMap[currentPath] || pageMap["/"]; useEffect( function syncDocumentTitle() { document.title = activePage.title; }, [activePage] ); return (
{activePage.render()}
); } ReactDOM.createRoot(document.getElementById("root")).render();