fix: use router instead of window.location to set hash

This commit is contained in:
Shariq Ansari 2024-09-28 19:52:03 +05:30
parent 2f58da93a6
commit 6be83291f3
2 changed files with 9 additions and 8 deletions

View File

@ -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() {

View File

@ -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()
}
})