diff --git a/src/store/modules/route/index.ts b/src/store/modules/route/index.ts index 46abf1497..94a374c4b 100644 --- a/src/store/modules/route/index.ts +++ b/src/store/modules/route/index.ts @@ -151,7 +151,7 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { await initDynamicAuthRoute(); } - tabStore.initHomeTab(router); + tabStore.initHomeTab(); } /** Init static auth route */ diff --git a/src/store/modules/tab/index.ts b/src/store/modules/tab/index.ts index bb93dc908..1add834ab 100644 --- a/src/store/modules/tab/index.ts +++ b/src/store/modules/tab/index.ts @@ -1,5 +1,5 @@ import { computed, ref } from 'vue'; -import type { Router } from 'vue-router'; +import { useRouter } from 'vue-router'; import { defineStore } from 'pinia'; import { useEventListener } from '@vueuse/core'; import { SetupStoreId } from '@/enum'; @@ -7,6 +7,7 @@ import { useRouterPush } from '@/hooks/common/router'; import { localStg } from '@/utils/storage'; import { useThemeStore } from '../theme'; import { + filterTabsByAllRoutes, filterTabsById, filterTabsByIds, getAllTabs, @@ -19,6 +20,7 @@ import { } from './shared'; export const useTabStore = defineStore(SetupStoreId.Tab, () => { + const router = useRouter(); const themeStore = useThemeStore(); const { routerPush } = useRouterPush(false); @@ -28,12 +30,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => { /** Get active tab */ const homeTab = ref(); - /** - * Init home tab - * - * @param router Router instance - */ - function initHomeTab(router: Router) { + /** Init home tab */ + function initHomeTab() { homeTab.value = getDefaultHomeTab(router); } @@ -61,7 +59,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => { const storageTabs = localStg.get('globalTabs'); if (themeStore.tab.cache && storageTabs) { - tabs.value = updateTabsByI18nKey(storageTabs); + const filteredTabs = filterTabsByAllRoutes(router, storageTabs); + tabs.value = updateTabsByI18nKey(filteredTabs); } addTab(currentRoute); diff --git a/src/store/modules/tab/shared.ts b/src/store/modules/tab/shared.ts index a7c3c627d..2036ef3cf 100644 --- a/src/store/modules/tab/shared.ts +++ b/src/store/modules/tab/shared.ts @@ -126,6 +126,20 @@ export function filterTabsByIds(tabIds: string[], tabs: App.Global.Tab[]) { return tabs.filter(tab => !tabIds.includes(tab.id)); } +/** + * filter tabs by all routes + * + * @param router + * @param tabs + */ +export function filterTabsByAllRoutes(router: Router, tabs: App.Global.Tab[]) { + const routes = router.getRoutes(); + + const routeNames = routes.map(route => route.name); + + return tabs.filter(tab => routeNames.includes(tab.routeKey)); +} + /** * Get fixed tabs *