File tree Expand file tree Collapse file tree 1 file changed +9
-0
lines changed
Expand file tree Collapse file tree 1 file changed +9
-0
lines changed Original file line number Diff line number Diff line change @@ -209,6 +209,7 @@ export const offsetTop = $el =>
209209
210210// Scroll an in-page link target into view
211211export const scrollTargetIntoView = ( event , href ) => {
212+ event . preventDefault ( )
212213 event . stopPropagation ( )
213214 // We use an attribute `querySelector()` rather than `getElementByID()`,
214215 // as some auto-generated ID's are invalid or not unique
@@ -223,6 +224,14 @@ export const scrollTargetIntoView = (event, href) => {
223224 $el . tabIndex = - 1
224225 // Focus the heading
225226 $el . focus ( )
227+ // Update the URL to show the hash without changing the current path
228+ const currentPath = window . location . pathname + window . location . search
229+ if ( history . pushState ) {
230+ history . pushState ( null , null , currentPath + '#' + id )
231+ } else {
232+ // Fallback for older browsers
233+ window . location . hash = id
234+ }
226235 } )
227236 }
228237}
You can’t perform that action at this time.
0 commit comments