nondestructive hash setting

master
bel 2022-02-09 22:30:01 -07:00
parent b6c1b3aeac
commit e0ead8f3c6
2 changed files with 10 additions and 3 deletions

View File

@ -1,4 +1,5 @@
todo:
- https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#change_a_query_parameter
- preview default via q param
- css
done:
- https://developer.mozilla.org/en-US/docs/Web/API/History/pushState#change_a_query_parameter

View File

@ -189,8 +189,14 @@
lastNavigateToQuery = new Date()
const url = new URL(window.location)
url.searchParams.set(k, v)
window.location.hash = "#?"+k+"="+v
//window.history.pushState({}, '', url)
var hash = "#?"
const it = url.searchParams.entries()
let result = it.next()
while (!result.done) {
hash = hash + result.value[0] + "=" + result.value[1] + "&"
result = it.next()
}
window.location.hash = hash
}
window.onhashchange = () => {