1
0
Fork 0
mirror of https://github.com/terribleplan/next.js.git synced 2024-01-19 02:48:18 +00:00

Implement the correct browser behavior for hash changes. (#2223)

This commit is contained in:
Arunoda Susiripala 2017-06-10 01:02:28 +05:30 committed by GitHub
parent 28b40a5d41
commit 0d4e0e52f7

View file

@ -132,9 +132,10 @@ export default class Router {
const { pathname, query } = parse(url, true)
// If the url change is only related to a hash change
// We should not proceed. We should only replace the state.
// We should not proceed. We should only change the state.
if (this.onlyAHashChange(as)) {
this.changeState('replaceState', url, as)
this.changeState(method, url, as)
this.scrollToHash(as)
return
}
@ -261,6 +262,14 @@ export default class Router {
return true
}
scrollToHash (as) {
const [ , hash ] = as.split('#')
const el = document.getElementById(hash)
if (el) {
el.scrollIntoView()
}
}
urlIsNew (pathname, query) {
return this.pathname !== pathname || !shallowEquals(query, this.query)
}