From b01b94269bbc104d336e7e8e5b38ea345ec1f762 Mon Sep 17 00:00:00 2001 From: davwas Date: Mon, 6 Nov 2023 10:59:15 +0100 Subject: [PATCH] BC-4550 - Browser back on page Tools does not lead to previous page (#2889) * fix bug by setting active tab again if page was served from cache --- src/pages/rooms/RoomDetails.page.vue | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/pages/rooms/RoomDetails.page.vue b/src/pages/rooms/RoomDetails.page.vue index 27b78c7596..3aeb27f6e7 100644 --- a/src/pages/rooms/RoomDetails.page.vue +++ b/src/pages/rooms/RoomDetails.page.vue @@ -407,7 +407,7 @@ export default defineComponent({ }, }, async created() { - if (this.$route.query && this.$route.query.tab) { + if (this.$route.query?.tab) { this.setActiveTab(this.$route.query.tab); } @@ -419,7 +419,22 @@ export default defineComponent({ document.title = buildPageTitle(this.roomData.title); }, + mounted() { + window.addEventListener("pageshow", this.setActiveTabIfPageCached); + }, + beforeDestroy() { + window.removeEventListener("pageshow", this.setActiveTabIfPageCached); + }, methods: { + setActiveTabIfPageCached(event) { + if (event.persisted) { + if (this.$route.query?.tab) { + this.setActiveTab(this.$route.query.tab); + } else { + this.setActiveTab("learn-content"); + } + } + }, setActiveTab(tabName) { const index = this.tabItems.findIndex( (tabItem) => tabItem.name === tabName @@ -494,7 +509,7 @@ export default defineComponent({ watch: { tabIndex(newIndex) { if (newIndex >= 0 && newIndex < this.tabItems.length) { - this.$router.replace({ + this.$router.push({ query: { ...this.$route.query, tab: this.tabItems[newIndex].name }, }); }