v4
This commit is contained in:
@@ -27,7 +27,7 @@ export default function useLayoutInit() {
|
||||
// Destroy ALL existing swiper instances to prevent duplicates
|
||||
document.querySelectorAll('.swiper').forEach(el => {
|
||||
if (el.swiper) {
|
||||
try { el.swiper.destroy(true, true) } catch (e) {}
|
||||
try { el.swiper.destroy(true, true) } catch (e) { console.warn('useLayoutInit: swiper destroy failed:', e) }
|
||||
}
|
||||
})
|
||||
|
||||
@@ -55,7 +55,7 @@ export default function useLayoutInit() {
|
||||
}
|
||||
rafId = requestAnimationFrame(poll)
|
||||
|
||||
// Fallback timeout (8 seconds)
|
||||
// Fallback timeout (3 seconds)
|
||||
const fallback = setTimeout(() => {
|
||||
if (!destroyed) {
|
||||
window.__layoutReady = true
|
||||
@@ -63,7 +63,7 @@ export default function useLayoutInit() {
|
||||
destroyed = true
|
||||
if (rafId) cancelAnimationFrame(rafId)
|
||||
}
|
||||
}, 8000)
|
||||
}, 3000)
|
||||
|
||||
return () => {
|
||||
destroyed = true
|
||||
|
||||
@@ -1,20 +1,6 @@
|
||||
import { useNavigate } from 'react-router-dom'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const postIdToSlug = {
|
||||
35: 'electro-mechanical-works',
|
||||
3159: 'landscaping-fencing-works',
|
||||
3160: 'metal-construction-fabrications',
|
||||
3172: 'building-contracting-works',
|
||||
3179: 'interior-fit-out-works',
|
||||
3186: 'chiller-hot-cool-solutions',
|
||||
3192: 'misting-solutions',
|
||||
3199: 'adiabatic-pre-cooling-system',
|
||||
3206: 'building-management-system',
|
||||
}
|
||||
|
||||
// Known SPA routes
|
||||
const spaRoutes = ['/', '/about', '/service', '/project', '/contact']
|
||||
import { SPA_ROUTES, POST_ID_TO_SLUG } from '../config'
|
||||
|
||||
export function useNavFix(ref) {
|
||||
const navigate = useNavigate()
|
||||
@@ -28,7 +14,7 @@ export function useNavFix(ref) {
|
||||
if (!link) return
|
||||
|
||||
let href = link.getAttribute('href')
|
||||
if (!href || href === '#' || href.startsWith('#')) return
|
||||
if (!href || href.startsWith('#')) return
|
||||
|
||||
// External links (http/https) — open in new tab if different host
|
||||
if (href.startsWith('http')) {
|
||||
@@ -38,7 +24,7 @@ export function useNavFix(ref) {
|
||||
e.preventDefault()
|
||||
window.open(href, '_blank', 'noopener,noreferrer')
|
||||
}
|
||||
} catch (_) {}
|
||||
} catch (_) { console.warn('useNavFix: failed to parse URL:', href) }
|
||||
return
|
||||
}
|
||||
|
||||
@@ -51,7 +37,7 @@ export function useNavFix(ref) {
|
||||
// Handle ?p= service links → SPA route
|
||||
const serviceMatch = route.match(/service\?p=(\d+)/)
|
||||
if (serviceMatch) {
|
||||
const slug = postIdToSlug[serviceMatch[1]]
|
||||
const slug = POST_ID_TO_SLUG[serviceMatch[1]]
|
||||
if (slug) {
|
||||
navigate('/service/' + slug)
|
||||
} else {
|
||||
@@ -71,7 +57,7 @@ export function useNavFix(ref) {
|
||||
|
||||
// If route matches known SPA routes or starts with /service/, navigate
|
||||
const normalizedRoute = '/' + route
|
||||
if (spaRoutes.includes(normalizedRoute) || normalizedRoute.startsWith('/service/')) {
|
||||
if (SPA_ROUTES.includes(normalizedRoute) || normalizedRoute.startsWith('/service/')) {
|
||||
navigate(normalizedRoute)
|
||||
return
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user