File tree Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Expand file tree Collapse file tree 2 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -72,6 +72,8 @@ import { HashLink } from 'react-router-hash-link';
72
72
``` js
73
73
import { HashLink } from ' react-router-hash-link' ;
74
74
< HashLink to= " /path#top" > Link to Top of Page< / HashLink>
75
+ // or
76
+ < HashLink to= " #top" > Link to Top of Page< / HashLink>
75
77
```
76
78
77
79
### Scroll with offset
Original file line number Diff line number Diff line change @@ -19,14 +19,19 @@ function reset() {
19
19
function getElAndScroll ( ) {
20
20
let element = null ;
21
21
if ( hashFragment === '#' ) {
22
- element = document . documentElement ;
22
+ // use document.body instead of document.documentElement because of a bug in smoothscroll-polyfill in safari
23
+ // see https://github.com/iamdustan/smoothscroll/issues/138
24
+ // while smoothscroll-polyfill is not included, it is the recommended way to implement smoothscroll
25
+ // in browsers that don't natively support el.scrollIntoView({ behavior: 'smooth' })
26
+ element = document . body ;
23
27
} else {
24
28
// check for element with matching id before assume '#top' is the top of the document
25
29
// see https://html.spec.whatwg.org/multipage/browsing-the-web.html#target-element
26
30
const id = hashFragment . replace ( '#' , '' ) ;
27
31
element = document . getElementById ( id ) ;
28
32
if ( element === null && hashFragment === '#top' ) {
29
- element = document . documentElement ;
33
+ // see above comment for why document.body instead of document.documentElement
34
+ element = document . body ;
30
35
}
31
36
}
32
37
You can’t perform that action at this time.
0 commit comments