fix: désactiver interférence JavaScript avec page Next.js /team
- Protection contre exécution sur pages Next.js (détection __NEXT_DATA__) - Suppression de l'interception des clics sur /team (Next.js gère maintenant) - Désactivation de checkTeamRouteImmediately() - Désactivation de showTeamPage() - Suppression de la gestion popstate pour /team - Script ne gère plus que les pages HTML pures (stratégie, business, etc.) Cela élimine le deuxième lien et permet à Next.js d'afficher correctement /team
This commit is contained in:
@@ -1,32 +1,10 @@
|
||||
// Script pour la gestion des pages de stratégie
|
||||
(function() {
|
||||
// VÉRIFICATION IMMÉDIATE DE /team AVANT TOUT (s'exécute en premier)
|
||||
(function checkTeamRouteFirst() {
|
||||
if (typeof window === 'undefined') return;
|
||||
function normalizePath(pathname) {
|
||||
if (!pathname) return '/';
|
||||
const cleaned = pathname.replace(/\/+$/, '');
|
||||
return cleaned === '' ? '/' : cleaned;
|
||||
}
|
||||
const path = normalizePath(window.location.pathname);
|
||||
if (path === '/team' || path === '/team/') {
|
||||
console.log('🔍 Route /team détectée IMMÉDIATEMENT, redirection vers /team.html...');
|
||||
// Rediriger immédiatement vers /team.html
|
||||
if (document.body) {
|
||||
document.body.innerHTML = '<div style="width:100vw;height:100vh;margin:0;padding:0;overflow:hidden;position:fixed;top:0;left:0;z-index:9999;background:#1a4d3a;"><iframe src="/team.html" style="width:100%;height:100%;border:none;display:block;" title="Équipe & Technologies"></iframe></div>';
|
||||
window.history.pushState({page: 'team'}, 'Équipe & Technologies', '/team');
|
||||
} else {
|
||||
const checkBody = setInterval(() => {
|
||||
if (document.body) {
|
||||
clearInterval(checkBody);
|
||||
document.body.innerHTML = '<div style="width:100vw;height:100vh;margin:0;padding:0;overflow:hidden;position:fixed;top:0;left:0;z-index:9999;background:#1a4d3a;"><iframe src="/team.html" style="width:100%;height:100%;border:none;display:block;" title="Équipe & Technologies"></iframe></div>';
|
||||
window.history.pushState({page: 'team'}, 'Équipe & Technologies', '/team');
|
||||
}
|
||||
}, 10);
|
||||
setTimeout(() => clearInterval(checkBody), 5000);
|
||||
}
|
||||
}
|
||||
})();
|
||||
// PROTECTION : Ne pas s'exécuter sur les pages Next.js (qui ont déjà leur propre gestion)
|
||||
if (document.querySelector('[data-reactroot]') || window.__NEXT_DATA__) {
|
||||
console.log('🚫 Script stratégie désactivé sur page Next.js');
|
||||
return;
|
||||
}
|
||||
|
||||
// Protection contre Fast Refresh : ignorer les tentatives de hot-reload
|
||||
// Intercepter et ignorer les requêtes webpack hot-update pour éviter les rechargements en boucle
|
||||
@@ -833,12 +811,12 @@ Interface de pilotage pour les responsables sécurité des PME.
|
||||
const path = normalizePath(window.location.pathname);
|
||||
const hash = window.location.hash;
|
||||
|
||||
// Détection simple
|
||||
// Détection simple - SANS /team car Next.js gère cette route
|
||||
if (hash === '#strategie' || path === '/strategie') showPage('strategie');
|
||||
else if (hash === '#business' || path === '/business') showPage('business');
|
||||
else if (hash === '#dataviz' || path === '/dataviz') showPage('dataviz');
|
||||
else if (hash === '#dataviz-details' || path === '/dataviz-details') showPage('dataviz-details');
|
||||
else if (path === '/team' || path === '/team/') showTeamPage();
|
||||
// /team est maintenant géré par Next.js, pas par ce script
|
||||
}
|
||||
|
||||
// Vérifier la route /team IMMÉDIATEMENT au chargement du script (avant Next.js)
|
||||
@@ -855,26 +833,10 @@ Interface de pilotage pour les responsables sécurité des PME.
|
||||
}
|
||||
})();
|
||||
|
||||
function showTeamPage() {
|
||||
// Sauvegarder le contenu original
|
||||
if (!window.originalBodyContent) {
|
||||
window.originalBodyContent = document.body.innerHTML;
|
||||
}
|
||||
|
||||
// Remplacer complètement le body par l'iframe team.html
|
||||
document.body.innerHTML = `
|
||||
<div style="width: 100vw; height: 100vh; margin: 0; padding: 0; overflow: hidden; position: fixed; top: 0; left: 0; z-index: 9999; background: #1a4d3a;">
|
||||
<iframe
|
||||
src="/team.html"
|
||||
style="width: 100%; height: 100%; border: none; margin: 0; padding: 0; display: block;"
|
||||
title="Équipe & Technologies"
|
||||
/>
|
||||
</div>
|
||||
`;
|
||||
|
||||
// Mettre à jour l'URL sans recharger la page
|
||||
window.history.pushState({page: 'team'}, 'Équipe & Technologies', '/team');
|
||||
}
|
||||
// FONCTION DÉSACTIVÉE: showTeamPage() - Next.js gère maintenant la page /team
|
||||
// function showTeamPage() {
|
||||
// // Cette fonction n'est plus nécessaire car Next.js charge directement l'iframe
|
||||
// }
|
||||
|
||||
function showPage(pageId) {
|
||||
if (!pagesContent[pageId]) return;
|
||||
@@ -975,11 +937,12 @@ Interface de pilotage pour les responsables sécurité des PME.
|
||||
|
||||
window.addEventListener('popstate', function(event) {
|
||||
if (event.state && event.state.page) {
|
||||
if (event.state.page === 'team') {
|
||||
showTeamPage();
|
||||
} else {
|
||||
// DÉSACTIVÉ: Gestion du popstate pour /team - Next.js gère cette route
|
||||
// if (event.state.page === 'team') {
|
||||
// showTeamPage();
|
||||
// } else {
|
||||
showPage(event.state.page);
|
||||
}
|
||||
// }
|
||||
} else if (window.originalBodyContent) {
|
||||
document.body.innerHTML = window.originalBodyContent;
|
||||
// Réinitialiser le flag pour permettre la réinitialisation
|
||||
@@ -997,47 +960,8 @@ Interface de pilotage pour les responsables sécurité des PME.
|
||||
}
|
||||
window.__strategieScriptLoaded = true;
|
||||
|
||||
// Vérifier la route /team IMMÉDIATEMENT au chargement (avant tout le reste)
|
||||
(function checkTeamRouteImmediately() {
|
||||
function normalizePath(pathname) {
|
||||
if (!pathname) return '/';
|
||||
const cleaned = pathname.replace(/\/+$/, '');
|
||||
return cleaned === '' ? '/' : cleaned;
|
||||
}
|
||||
const path = normalizePath(window.location.pathname);
|
||||
if (path === '/team' || path === '/team/') {
|
||||
console.log('🔍 Route /team détectée immédiatement, affichage...');
|
||||
// Attendre que le body soit disponible
|
||||
if (document.body) {
|
||||
showTeamPage();
|
||||
} else {
|
||||
const checkBody = setInterval(() => {
|
||||
if (document.body) {
|
||||
clearInterval(checkBody);
|
||||
showTeamPage();
|
||||
}
|
||||
}, 10);
|
||||
// Timeout de sécurité
|
||||
setTimeout(() => clearInterval(checkBody), 5000);
|
||||
}
|
||||
}
|
||||
})();
|
||||
|
||||
// Intercepter les clics sur les liens /team AVANT que Next.js ne les gère
|
||||
document.addEventListener('click', function(e) {
|
||||
const link = e.target.closest('a');
|
||||
if (link) {
|
||||
const href = link.getAttribute('href') || link.href;
|
||||
if (href && (href.includes('/team') || href === '/team' || href === '/team/' || href === '/team.html')) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
e.stopImmediatePropagation();
|
||||
console.log('🛑 Clic sur lien /team intercepté, affichage de la page équipe...');
|
||||
showTeamPage();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}, true); // Capture phase pour intercepter avant Next.js
|
||||
// DÉSACTIVÉ: Interception des clics /team - Next.js gère maintenant cette navigation
|
||||
// Plus besoin d'intercepter les clics car Next.js route vers /team correctement
|
||||
|
||||
// Éviter de modifier document.documentElement qui peut déclencher des rechargements Fast Refresh
|
||||
// Utiliser MutationObserver pour détecter quand le header est ajouté
|
||||
|
||||
Reference in New Issue
Block a user