@@ -44,16 +44,28 @@ class Router {
4444 this . navigate ( window . location . pathname , false ) ;
4545 } ) ;
4646
47- // Intercept link clicks
47+ // Intercept all clicks at the document level (including those from Shadow DOM)
4848 document . addEventListener ( 'click' , ( e ) => {
49- // Find closest anchor element
50- const anchor = e . target . closest ( 'a' ) ;
49+ // Check if the click path includes an anchor element
50+ // This works for both regular DOM and shadow DOM
51+ let anchor = null ;
52+ let path = e . composedPath ( ) ;
53+
54+ // Find the first anchor element in the event path
55+ for ( let i = 0 ; i < path . length ; i ++ ) {
56+ if ( path [ i ] . tagName === 'A' ) {
57+ anchor = path [ i ] ;
58+ break ;
59+ }
60+ }
5161
5262 // Skip if no anchor or if modifier keys are pressed
5363 if ( ! anchor || e . metaKey || e . ctrlKey || e . shiftKey ) return ;
5464
55- // Skip if it's an external link or has a target
65+ // Get the href attribute
5666 const href = anchor . getAttribute ( 'href' ) ;
67+
68+ // Skip if it's an external link or has a target
5769 if ( ! href || href . startsWith ( 'http' ) || href . startsWith ( '//' ) || anchor . hasAttribute ( 'target' ) ) return ;
5870
5971 // Skip if it's a download link
@@ -70,7 +82,9 @@ class Router {
7082
7183 // Navigate to the link
7284 this . navigate ( href ) ;
73- } ) ;
85+
86+ console . log ( 'Intercepted click on link:' , href ) ;
87+ } , { capture : true } ) ; // Use capture to get events before they reach the shadow DOM
7488 }
7589
7690 /**
0 commit comments