Navigation Page Indicator Fix
Navigation Page Indicator Fix
Problem
The navigation page indicators (active states) were not updating properly during Swup page transitions. The is-active
class would be removed after internal page navigation.
Root Cause Analysis
The issue occurred because:
- Swup page transitions change the URL and DOM content
- The navigation active state detection logic needed to be more robust
- Timing issues between content replacement and navigation updates
- The navigation update function needed better URL path matching
Solutions Implemented
1. Enhanced Navigation Active State Detection
File: assets/js/swup-modern-clean.js
Improvements:
- More comprehensive path matching logic
- Multiple fallback detection methods:
- Direct URL path matching
- Meta tag category detection
- Body class inspection
- Page title analysis
- Better logging for debugging
- Handles trailing slashes and edge cases
2. Multiple Update Triggers
Added navigation updates at several points:
content:replace
hook (immediate)page:view
hook (after content loaded)- Delayed fallback updates (50ms, 500ms)
- Browser navigation events (
popstate
,hashchange
)
3. Debug Tools Added
Global Functions Available:
debugNavigation()
- Full diagnostic informationupdateNavigation()
- Manual navigation state update
Debug File Created: test-navigation-debug.html
- Visual debug panel
- Real-time navigation state checking
- Console output capture
- Manual testing tools
4. Robust Link Matching
The navigation update now tries multiple methods to find the correct nav links:
href
attribute contains section namehref
attribute ends with section name- Link text matches section name
- Absolute URL matching
Testing Instructions
Method 1: Browser Console
- Open your site in a browser
- Navigate between pages using Swup (internal links)
- Open developer console
- Run
debugNavigation()
to see detailed status - Run
updateNavigation()
to manually force update
Method 2: Debug Panel
- Open
test-navigation-debug.html
in a separate tab - Open your main site in another tab
- Navigate between pages on main site
- Use debug panel to check navigation states
Method 3: Console Monitoring
- Open developer console on your site
- Navigate between pages
- Watch for navigation update logs:
🧭 ModernSwup: Updating navigation active states
✅ Navigation update complete
- Any error messages
Expected Behavior
- Navigation links should show active state immediately after page transitions
- Active states should persist during animations
- Console should show successful navigation updates
- Multiple fallback triggers ensure reliability
Troubleshooting
If Navigation Still Not Working:
- Check Console for Errors:
debugNavigation()
- Verify Swup Instance:
console.log(window.swupInstance)
- Manual Force Update:
updateNavigation()
-
Check CSS Active Styles: Ensure
.nav-link.is-active
and.mobile-nav-link.is-active
styles are defined - Verify Link Structure:
Navigation links should have
href
attributes that match the section paths
Files Modified
assets/js/swup-modern-clean.js
- Main navigation logictest-navigation-debug.html
- Debug tools (new file)
Performance Impact
Minimal - navigation updates are lightweight DOM operations with intelligent timing to avoid conflicts with page transitions.