diff --git a/lib/router/router.js b/lib/router/router.js index a5197288..0b560cf2 100644 --- a/lib/router/router.js +++ b/lib/router/router.js @@ -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) }