From cdd6e1c573c456cb8fc39c08b0989ad8390d90e8 Mon Sep 17 00:00:00 2001 From: syoul Date: Tue, 9 Dec 2025 19:26:54 +0100 Subject: [PATCH] Fix: detection navigation SPA pour page team --- public/team-block-script.js | 39 +++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/public/team-block-script.js b/public/team-block-script.js index 83a0bb3..7d5c5c3 100644 --- a/public/team-block-script.js +++ b/public/team-block-script.js @@ -2,14 +2,27 @@ (function() { 'use strict'; - var path = window.location.pathname; - var isTeamRoute = path === '/team' || path === '/team/' || path.startsWith('/team/'); - - if (!isTeamRoute) { - return; + // Fonction pour verifier si on est sur la route team + function isTeamRoute() { + var path = window.location.pathname; + return path === '/team' || path === '/team/' || path.startsWith('/team/'); } - console.log('EQUIPE: Page team detectee, preparation du remplacement DOM'); + // Fonction pour verifier et initialiser la page team + function checkAndInitTeamPage() { + if (!isTeamRoute()) { + return; + } + + // Eviter double initialisation + if (window.__teamPageInitialized) { + return; + } + window.__teamPageInitialized = true; + + console.log('EQUIPE: Page team detectee, preparation du remplacement DOM'); + initTeamPage(); + } // Fonction pour charger un script externe function loadScript(src) { @@ -321,8 +334,18 @@ // Demarrer quand le DOM est pret if (document.readyState === 'loading') { - document.addEventListener('DOMContentLoaded', initTeamPage); + document.addEventListener('DOMContentLoaded', checkAndInitTeamPage); } else { - initTeamPage(); + checkAndInitTeamPage(); } + + // Detecter les navigations Next.js (SPA) + var lastUrl = location.href; + new MutationObserver(function() { + if (location.href !== lastUrl) { + lastUrl = location.href; + window.__teamPageInitialized = false; + checkAndInitTeamPage(); + } + }).observe(document, { subtree: true, childList: true }); })();