Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Keep URL hash across page transition, and jump to named element if present #31

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/History.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,16 @@ History.prototype._update = function(historyMethod, relativeUrl, render, state,
var options = renderOptions(e, path)
state.$render = true
state.$method = options.method
window.history[historyMethod](state, null, options.url)
window.history[historyMethod](state, null, options.url + (url.hash || ''))
currentPath = window.location.pathname + window.location.search
if (render) router.render(this, options, e)
// Jump to named element on new page, to mimic browser behavior
if (url.hash) {
var hashElement = document.getElementById(url.hash.substring(1))
if (hashElement) {
hashElement.scrollIntoView()
}
}
}

History.prototype.page = function() {
Expand Down