From 3ecb0f668e83fd0c40800526a248fa396c993221 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Fri, 27 Jan 2023 16:42:20 +0100 Subject: [PATCH] Use `replaceState` and simplify updating search params --- src/components/ChannelPage.vue | 6 +++++- src/main.js | 12 ------------ 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/src/components/ChannelPage.vue b/src/components/ChannelPage.vue index 4bce5531..95bbdeef 100644 --- a/src/components/ChannelPage.vue +++ b/src/components/ChannelPage.vue @@ -224,7 +224,11 @@ export default { }, loadTab(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) { this.contentItems = this.channel.relatedStreams; diff --git a/src/main.js b/src/main.js index 67538926..12cf63ef 100644 --- a/src/main.js +++ b/src/main.js @@ -251,18 +251,6 @@ const mixin = { elem.click(); 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: { authenticated(_this) {