fix: use router instead of window.location to set hash
This commit is contained in:
parent
2f58da93a6
commit
6be83291f3
@ -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() {
|
||||
|
||||
@ -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()
|
||||
}
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user