Skip to content

Commit 31feced

Browse files
jxodwyernkzawa
authored andcommitted
Avoid autoscrolling anchored URLs (vercel#474)
* force scroll to false if # is found in url * only overwrite scroll if scroll=true is not passed in * clean up logic around setting scroll var
1 parent eb9a61e commit 31feced

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

lib/link.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class Link extends Component {
1414
return
1515
}
1616

17-
const { href, scroll, as } = this.props
17+
const { href, as } = this.props
1818

1919
if (!isLocal(href)) {
2020
// ignore click if it's outside our scope
@@ -26,6 +26,12 @@ export default class Link extends Component {
2626
const route = as ? href : null
2727
const url = as || href
2828

29+
// avoid scroll for urls with anchor refs
30+
let { scroll } = this.props
31+
if (scroll == null) {
32+
scroll = url.indexOf('#') < 0
33+
}
34+
2935
// straight up redirect
3036
Router.push(route, url)
3137
.then((success) => {

0 commit comments

Comments
 (0)