Use replaceState and simplify updating search params

This commit is contained in:
Bnyro 2023-01-27 16:42:20 +01:00
parent 7f72485a04
commit 3ecb0f668e
2 changed files with 5 additions and 13 deletions

View File

@ -224,7 +224,11 @@ export default {
}, },
loadTab(index) { loadTab(index) {
this.selectedTab = index; this.selectedTab = index;
this.appendQueryToUrl("tab", this.tabs[index].name ?? "videos");
// update the tab query in the url path
const url = new URL(window.location);
url.searchParams.set("tab", this.tabs[index].name ?? "videos");
window.history.replaceState(window.history.state, "", url);
if (index == 0) { if (index == 0) {
this.contentItems = this.channel.relatedStreams; this.contentItems = this.channel.relatedStreams;

View File

@ -251,18 +251,6 @@ const mixin = {
elem.click(); elem.click();
elem.remove(); elem.remove();
}, },
appendQueryToUrl(key, value) {
let searchParams = new URLSearchParams(window.location.search);
searchParams.set(key, value);
let newurl =
window.location.protocol +
"//" +
window.location.host +
window.location.pathname +
"?" +
searchParams.toString();
window.history.pushState({ path: newurl }, "", newurl);
},
}, },
computed: { computed: {
authenticated(_this) { authenticated(_this) {