Skip to content

Commit

Permalink
fix(projects): fix useRouter in tab store
Browse files Browse the repository at this point in the history
  • Loading branch information
honghuangdc committed Jun 6, 2024
1 parent 40cebab commit 962c403
Showing 1 changed file with 7 additions and 10 deletions.
17 changes: 7 additions & 10 deletions src/store/modules/tab/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { computed, ref } from 'vue';
import { useRouter } from 'vue-router';
import { defineStore } from 'pinia';
import { useEventListener } from '@vueuse/core';
import type { RouteKey } from '@elegant-router/types';
import { router } from '@/router';
import { SetupStoreId } from '@/enum';
import { useRouterPush } from '@/hooks/common/router';
import { localStg } from '@/utils/storage';
Expand All @@ -17,13 +17,13 @@ import {
getDefaultHomeTab,
getFixedTabIds,
getTabByRoute,
getTabIdByRoute,
isTabInTabs,
updateTabByI18nKey,
updateTabsByI18nKey
} from './shared';

export const useTabStore = defineStore(SetupStoreId.Tab, () => {
const router = useRouter();
const routeStore = useRouteStore();
const themeStore = useThemeStore();
const { routerPush } = useRouterPush(false);
Expand All @@ -34,11 +34,7 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
/** Get active tab */
const homeTab = ref<App.Global.Tab>();

/**
* Init home tab
*
* @param router Router instance
*/
/** Init home tab */
function initHomeTab() {
homeTab.value = getDefaultHomeTab(router, routeStore.routeHome);
}
Expand Down Expand Up @@ -67,8 +63,8 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
const storageTabs = localStg.get('globalTabs');

if (themeStore.tab.cache && storageTabs) {
const filteredTabs = extractTabsByAllRoutes(router, storageTabs);
tabs.value = updateTabsByI18nKey(filteredTabs);
const extractedTabs = extractTabsByAllRoutes(router, storageTabs);
tabs.value = updateTabsByI18nKey(extractedTabs);
}

addTab(currentRoute);
Expand Down Expand Up @@ -293,6 +289,7 @@ export const useTabStore = defineStore(SetupStoreId.Tab, () => {
setTabLabel,
resetTabLabel,
isTabRetain,
updateTabsByLocale
updateTabsByLocale,
getTabIdByRoute
};
});

0 comments on commit 962c403

Please sign in to comment.