Commit 0d4e0e52 authored by Arunoda Susiripala's avatar Arunoda Susiripala Committed by GitHub

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

parent 28b40a5d
...@@ -132,9 +132,10 @@ export default class Router { ...@@ -132,9 +132,10 @@ export default class Router {
const { pathname, query } = parse(url, true) const { pathname, query } = parse(url, true)
// If the url change is only related to a hash change // 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)) { if (this.onlyAHashChange(as)) {
this.changeState('replaceState', url, as) this.changeState(method, url, as)
this.scrollToHash(as)
return return
} }
...@@ -261,6 +262,14 @@ export default class Router { ...@@ -261,6 +262,14 @@ export default class Router {
return true return true
} }
scrollToHash (as) {
const [ , hash ] = as.split('#')
const el = document.getElementById(hash)
if (el) {
el.scrollIntoView()
}
}
urlIsNew (pathname, query) { urlIsNew (pathname, query) {
return this.pathname !== pathname || !shallowEquals(query, this.query) return this.pathname !== pathname || !shallowEquals(query, this.query)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment