From 59faf1522969387b5e2e0a1b5d6665432b311606 Mon Sep 17 00:00:00 2001 From: Soybean Date: Sun, 2 Jun 2024 01:14:48 +0800 Subject: [PATCH] fix(projects): fix reCacheRoute. fixed #464 --- src/store/modules/route/index.ts | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/store/modules/route/index.ts b/src/store/modules/route/index.ts index 1acaf69f..d49b756b 100644 --- a/src/store/modules/route/index.ts +++ b/src/store/modules/route/index.ts @@ -97,13 +97,19 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { /** Cache routes */ const cacheRoutes = ref([]); + /** All cache routes */ + const allCacheRoutes = shallowRef([]); + /** * Get cache routes * * @param routes Vue routes */ function getCacheRoutes(routes: RouteRecordRaw[]) { - cacheRoutes.value = getCacheRouteNames(routes); + const alls = getCacheRouteNames(routes); + + cacheRoutes.value = alls; + allCacheRoutes.value = [...alls]; } /** @@ -130,12 +136,23 @@ export const useRouteStore = defineStore(SetupStoreId.Route, () => { cacheRoutes.value.splice(index, 1); } + /** + * Is cached route + * + * @param routeKey + */ + function isCachedRoute(routeKey: RouteKey) { + return allCacheRoutes.value.includes(routeKey); + } + /** * Re cache routes by route key * * @param routeKey */ async function reCacheRoutesByKey(routeKey: RouteKey) { + if (!isCachedRoute(routeKey)) return; + removeCacheRoutes(routeKey); await appStore.reloadPage();