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
|
// Script pour la gestion des pages de stratégie
|
||||||
(function() {
|
(function() {
|
||||||
// VÉRIFICATION IMMÉDIATE DE /team AVANT TOUT (s'exécute en premier)
|
// PROTECTION : Ne pas s'exécuter sur les pages Next.js (qui ont déjà leur propre gestion)
|
||||||
(function checkTeamRouteFirst() {
|
if (document.querySelector('[data-reactroot]') || window.__NEXT_DATA__) {
|
||||||
if (typeof window === 'undefined') return;
|
console.log('🚫 Script stratégie désactivé sur page Next.js');
|
||||||
function normalizePath(pathname) {
|
return;
|
||||||
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 contre Fast Refresh : ignorer les tentatives de hot-reload
|
// 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
|
// Intercepter et ignorer les requêtes webpack hot-update pour éviter les rechargements en boucle
|
||||||
@@ -832,13 +810,13 @@ Interface de pilotage pour les responsables sécurité des PME.
|
|||||||
function handleRoute() {
|
function handleRoute() {
|
||||||
const path = normalizePath(window.location.pathname);
|
const path = normalizePath(window.location.pathname);
|
||||||
const hash = window.location.hash;
|
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');
|
if (hash === '#strategie' || path === '/strategie') showPage('strategie');
|
||||||
else if (hash === '#business' || path === '/business') showPage('business');
|
else if (hash === '#business' || path === '/business') showPage('business');
|
||||||
else if (hash === '#dataviz' || path === '/dataviz') showPage('dataviz');
|
else if (hash === '#dataviz' || path === '/dataviz') showPage('dataviz');
|
||||||
else if (hash === '#dataviz-details' || path === '/dataviz-details') showPage('dataviz-details');
|
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)
|
// 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() {
|
// FONCTION DÉSACTIVÉE: showTeamPage() - Next.js gère maintenant la page /team
|
||||||
// Sauvegarder le contenu original
|
// function showTeamPage() {
|
||||||
if (!window.originalBodyContent) {
|
// // Cette fonction n'est plus nécessaire car Next.js charge directement l'iframe
|
||||||
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');
|
|
||||||
}
|
|
||||||
|
|
||||||
function showPage(pageId) {
|
function showPage(pageId) {
|
||||||
if (!pagesContent[pageId]) return;
|
if (!pagesContent[pageId]) return;
|
||||||
@@ -975,11 +937,12 @@ Interface de pilotage pour les responsables sécurité des PME.
|
|||||||
|
|
||||||
window.addEventListener('popstate', function(event) {
|
window.addEventListener('popstate', function(event) {
|
||||||
if (event.state && event.state.page) {
|
if (event.state && event.state.page) {
|
||||||
if (event.state.page === 'team') {
|
// DÉSACTIVÉ: Gestion du popstate pour /team - Next.js gère cette route
|
||||||
showTeamPage();
|
// if (event.state.page === 'team') {
|
||||||
} else {
|
// showTeamPage();
|
||||||
|
// } else {
|
||||||
showPage(event.state.page);
|
showPage(event.state.page);
|
||||||
}
|
// }
|
||||||
} else if (window.originalBodyContent) {
|
} else if (window.originalBodyContent) {
|
||||||
document.body.innerHTML = window.originalBodyContent;
|
document.body.innerHTML = window.originalBodyContent;
|
||||||
// Réinitialiser le flag pour permettre la réinitialisation
|
// 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;
|
window.__strategieScriptLoaded = true;
|
||||||
|
|
||||||
// Vérifier la route /team IMMÉDIATEMENT au chargement (avant tout le reste)
|
// DÉSACTIVÉ: Interception des clics /team - Next.js gère maintenant cette navigation
|
||||||
(function checkTeamRouteImmediately() {
|
// Plus besoin d'intercepter les clics car Next.js route vers /team correctement
|
||||||
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
|
|
||||||
|
|
||||||
// Éviter de modifier document.documentElement qui peut déclencher des rechargements Fast Refresh
|
// Éviter de modifier document.documentElement qui peut déclencher des rechargements Fast Refresh
|
||||||
// Utiliser MutationObserver pour détecter quand le header est ajouté
|
// Utiliser MutationObserver pour détecter quand le header est ajouté
|
||||||
|
|||||||
Reference in New Issue
Block a user