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 { ref, watch } from 'vue'
|
||||||
import { useRoute } from 'vue-router'
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useDebounceFn, useStorage } from '@vueuse/core'
|
import { useDebounceFn, useStorage } from '@vueuse/core'
|
||||||
|
|
||||||
export function useActiveTabManager(tabs, storageKey) {
|
export function useActiveTabManager(tabs, storageKey) {
|
||||||
const activieTab = useStorage(storageKey, 'activity')
|
const activieTab = useStorage(storageKey, 'activity')
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const preserveLastVisitedTab = useDebounceFn((tabName) => {
|
const preserveLastVisitedTab = useDebounceFn((tabName) => {
|
||||||
activieTab.value = tabName.toLowerCase()
|
activieTab.value = tabName.toLowerCase()
|
||||||
}, 300)
|
}, 300)
|
||||||
|
|
||||||
function setActiveTabInUrl(tabName) {
|
function setActiveTabInUrl(tabName) {
|
||||||
window.location.hash = '#' + tabName.toLowerCase()
|
let hash = '#' + tabName.toLowerCase()
|
||||||
|
router.push({ ...route, hash })
|
||||||
}
|
}
|
||||||
|
|
||||||
function getActiveTabFromUrl() {
|
function getActiveTabFromUrl() {
|
||||||
|
|||||||
@ -148,13 +148,12 @@ router.beforeEach(async (to, from, next) => {
|
|||||||
window.location.href = '/login?redirect-to=/crm'
|
window.location.href = '/login?redirect-to=/crm'
|
||||||
} else if (to.matched.length === 0) {
|
} else if (to.matched.length === 0) {
|
||||||
next({ name: 'Invalid Page' })
|
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 {
|
} 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()
|
next()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user