mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Avoid autoscrolling anchored URLs (#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
This commit is contained in:
parent
eb9a61e9e7
commit
31feced24a
|
@ -14,7 +14,7 @@ export default class Link extends Component {
|
|||
return
|
||||
}
|
||||
|
||||
const { href, scroll, as } = this.props
|
||||
const { href, as } = this.props
|
||||
|
||||
if (!isLocal(href)) {
|
||||
// ignore click if it's outside our scope
|
||||
|
@ -26,6 +26,12 @@ export default class Link extends Component {
|
|||
const route = as ? href : null
|
||||
const url = as || href
|
||||
|
||||
// avoid scroll for urls with anchor refs
|
||||
let { scroll } = this.props
|
||||
if (scroll == null) {
|
||||
scroll = url.indexOf('#') < 0
|
||||
}
|
||||
|
||||
// straight up redirect
|
||||
Router.push(route, url)
|
||||
.then((success) => {
|
||||
|
|
Loading…
Reference in a new issue