zhengyiming
2025-03-03 dfb8f993f691eedc558d52347b1a93a105f6b0d2
apps/taro/src/hooks/router.ts
@@ -1,6 +1,8 @@
import Taro from '@tarojs/taro';
import { TabBarPageRouter } from '@/constants';
import { useSystemStore } from '@/stores/modules/system';
import { useAppStore } from '@/stores/modules/app';
import { isInAlipay } from '@/utils/env';
export function useSwitchTab() {
  const systemStore = useSystemStore();
@@ -41,3 +43,28 @@
    isFocus,
  };
}
export function useTabRouteEnhance() {
  const appStore = useAppStore();
  const { latestRoute } = storeToRefs(appStore);
  const router = Taro.useRouter();
  Taro.useDidShow(() => {
    const isTabbarPage = Object.values(TabBarPageRouter).some((x) =>
      latestRoute.value.toLowerCase().includes(x.toLowerCase())
    );
    if (isTabbarPage && isInAlipay) {
      Taro.reLaunch({
        url: router.path,
        success() {
          appStore.setLatestRoute('');
        },
      });
    }
  });
  Taro.useDidHide(() => {
    appStore.setLatestRoute(router.path);
  });
}