diff --git a/frontend/src/composables/useActiveTabManager.js b/frontend/src/composables/useActiveTabManager.js index 4fffdedf..3de4c48f 100644 --- a/frontend/src/composables/useActiveTabManager.js +++ b/frontend/src/composables/useActiveTabManager.js @@ -1,17 +1,19 @@ import { ref, watch } from 'vue' -import { useRoute } from 'vue-router' +import { useRoute, useRouter } from 'vue-router' import { useDebounceFn, useStorage } from '@vueuse/core' export function useActiveTabManager(tabs, storageKey) { const activieTab = useStorage(storageKey, 'activity') const route = useRoute() + const router = useRouter() const preserveLastVisitedTab = useDebounceFn((tabName) => { activieTab.value = tabName.toLowerCase() }, 300) function setActiveTabInUrl(tabName) { - window.location.hash = '#' + tabName.toLowerCase() + let hash = '#' + tabName.toLowerCase() + router.push({ ...route, hash }) } function getActiveTabFromUrl() { diff --git a/frontend/src/router.js b/frontend/src/router.js index 2cb37387..3c7e9604 100644 --- a/frontend/src/router.js +++ b/frontend/src/router.js @@ -148,13 +148,12 @@ router.beforeEach(async (to, from, next) => { window.location.href = '/login?redirect-to=/crm' } else if (to.matched.length === 0) { next({ name: 'Invalid Page' }) + } else if (['Deal', 'Lead'].includes(to.name) && !to.hash) { + let storageKey = to.name === 'Deal' ? 'lastDealTab' : 'lastLeadTab' + const activeTab = localStorage.getItem(storageKey) || 'activity' + const hash = '#' + activeTab + next({ ...to, hash }) } else { - if (['Deal', 'Lead'].includes(to.name) && !to.hash) { - let storageKey = to.name === 'Deal' ? 'lastDealTab' : 'lastLeadTab' - const activeTab = localStorage.getItem(storageKey) || 'activity' - const hash = '#' + activeTab - next({ ...to, hash }) - } next() } })