Jelajahi Sumber

跳到hash 路由返回 sprots 会跳到首页

zhejiushizhuce 2 tahun lalu
induk
melakukan
7014ffca5b
1 mengubah file dengan 22 tambahan dan 2 penghapusan
  1. 22 2
      src/widgets/WSport/index.jsx

+ 22 - 2
src/widgets/WSport/index.jsx

@@ -9,7 +9,8 @@ import {ROUTE_PATH} from "@constants/routes";
 import {reqGameInfo} from "@features/api";
 const i18n=global.i18n;
 const objInfo={
-    bt:null
+    bt:null,
+    timer:null
 }
 const WSport=({})=>{
     const {isMobile}=useThemeProvider();
@@ -20,7 +21,7 @@ const WSport=({})=>{
     const language=i18n.language;
     const navigate=useNavigate();
     const dispatch=useDispatch();
-    const {pathname} = useLocation();
+    const {pathname,hash} = useLocation();
     const tempSPath=pathname.startsWith(ROUTE_PATH.RACING)?"/horse-racing-55":"/";
     const [sportPath,setSportPath]=useState(tempSPath)
     const refreshToken=async ()=>{
@@ -84,6 +85,12 @@ const WSport=({})=>{
             objInfo.bt=null;
         }
     }
+    const clearTimer=()=>{
+        if (objInfo.timer!=null){
+            clearTimeout(objInfo.timer);
+            objInfo.timer=null;
+        }
+    }
     useEffect(()=>{
         if (pathname.startsWith(ROUTE_PATH.SPORTS)){
             let sub=pathname.replace(ROUTE_PATH.SPORTS,"");
@@ -107,6 +114,18 @@ const WSport=({})=>{
             }
         }
     },[pathname])
+    useEffect(()=>{
+        if (hash===""){
+            clearTimer();
+            objInfo.timer=setTimeout(()=>{
+                if (objInfo.bt){
+                    objInfo.bt.updateOptions({
+                        url:sportPath
+                    })
+                }
+            },20);
+        }
+    },[hash])
     useEffect(()=>{
         if (objInfo.bt){
             if (bbConf==null)return null;
@@ -131,6 +150,7 @@ const WSport=({})=>{
         objInfo.bt=initBetby();
         return ()=>{
             clearBT();
+            clearTimer();
         }
     },[userID])
     //,theme,language