wujingjing
2024-10-30 03080e12de7de3fec89b2f77fcf9f73c02bc6cf0
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);
};
/**