gerson
2024-12-22 2ffb9f460e73eb28980c7d19b7cec417c942f750
src/utils/route.ts
@@ -9,25 +9,16 @@
/**
 * 按路由名称跳转至指定路由
 * 路由已缓存时,会清除缓存
 * 看 meta 设置的参数,判断是否需要设置路由缓存
 * @param routeLocation 路由位置,与 router.push 参数一致
 */
export const gotoRoute = (routeLocation: RouteLocationName) => {
   const storesKeepAliveNames = useKeepALiveNames();
   const routeName = routeLocation.name;
   const { cachedViews } = storeToRefs(storesKeepAliveNames);
   const isInclude = cachedViews.value.includes(routeName);
   if (isInclude) {
      storesKeepAliveNames.delCachedView({
         name: routeName,
      });
   }
   router.push(routeLocation).then(() => {
      if (isInclude) {
         cachedViews.value.push(routeName);
      }
   });
   const storesKeepAliveNames = useKeepALiveNames();
   const gotoRoute = router.getRoutes().find((item) => item.name === routeName);
   storesKeepAliveNames.addCachedView(gotoRoute)
   router.push(routeLocation);
};
/**