File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -368,7 +368,10 @@ function bindAnchorSelection() {
368368
369369function handleAnchorSelection ( event ) {
370370 const { anchorId } = event . detail
371- getAnchorModalModule ( ) . then ( ( { showAnchorDetails } ) => showAnchorDetails ( anchorId ) )
371+ // Navigate to the anchor route instead of opening the modal directly: the
372+ // URL then reflects the open anchor (deep-linkable, Back closes it), and the
373+ // router records it as a pageview so we can see which anchors are opened.
374+ navigate ( `/anchor/${ anchorId } ` )
372375}
373376
374377function initCardGridVisualization ( ) {
Original file line number Diff line number Diff line change @@ -159,6 +159,16 @@ function trackPageview() {
159159 }
160160}
161161
162+ // Close the anchor modal if it is open. Called when a non-anchor route is
163+ // resolved so the modal doesn't linger over the page after Back/forward or
164+ // in-app navigation. On a non-anchor route closeModal() does not touch the URL.
165+ function closeOpenAnchorModal ( ) {
166+ const modal = typeof document !== 'undefined' ? document . getElementById ( 'anchor-modal' ) : null
167+ if ( modal && ! modal . classList . contains ( 'hidden' ) ) {
168+ import ( '../components/anchor-modal.js' ) . then ( ( { closeModal } ) => closeModal ( ) )
169+ }
170+ }
171+
162172function handleRoute ( ) {
163173 let path = getCurrentRoute ( )
164174
@@ -202,6 +212,10 @@ function handleRoute() {
202212 return
203213 }
204214
215+ // Leaving an anchor route: close any open anchor modal so Back/forward and
216+ // in-app navigation don't leave it stranded as an overlay over the page.
217+ closeOpenAnchorModal ( )
218+
205219 const handler = routes . get ( path )
206220
207221 if ( typeof handler === 'function' ) {
You can’t perform that action at this time.
0 commit comments