File tree 1 file changed +9
-0
lines changed 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 =>
209
209
210
210
// Scroll an in-page link target into view
211
211
export const scrollTargetIntoView = ( event , href ) => {
212
+ event . preventDefault ( )
212
213
event . stopPropagation ( )
213
214
// We use an attribute `querySelector()` rather than `getElementByID()`,
214
215
// as some auto-generated ID's are invalid or not unique
@@ -223,6 +224,14 @@ export const scrollTargetIntoView = (event, href) => {
223
224
$el . tabIndex = - 1
224
225
// Focus the heading
225
226
$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
+ }
226
235
} )
227
236
}
228
237
}
You can’t perform that action at this time.
0 commit comments