|
|
@@ -1,6 +1,6 @@
|
|
|
import AllComponents, {Header} from '@pages/index';
|
|
|
import {Route, Routes, useNavigate} from 'react-router-dom';
|
|
|
-import React, {cloneElement, lazy, Suspense} from "react";
|
|
|
+import React, {cloneElement, Fragment, lazy, Suspense} from "react";
|
|
|
import SmallLoading from "@components/SmallLoading";
|
|
|
import TransitionGroup from "react-transition-group/TransitionGroup";
|
|
|
import CSSTransition from "react-transition-group/CSSTransition";
|
|
|
@@ -27,16 +27,12 @@ const CreateRoute=(props)=>{
|
|
|
)
|
|
|
}
|
|
|
return (
|
|
|
- <>
|
|
|
- <Route
|
|
|
- key={route.path}
|
|
|
- exact
|
|
|
- path={topath}
|
|
|
- element={checkLogin()}
|
|
|
- >
|
|
|
-
|
|
|
- </Route>
|
|
|
- </>
|
|
|
+ <Route
|
|
|
+ key={route.path}
|
|
|
+ exact
|
|
|
+ path={topath}
|
|
|
+ element={checkLogin()}
|
|
|
+ />
|
|
|
)
|
|
|
}
|
|
|
|
|
|
@@ -44,10 +40,10 @@ const CBrowserRouter=(props)=>{
|
|
|
const {routes,isLogin}=props;
|
|
|
return (
|
|
|
<Routes>
|
|
|
- <Route path="*" element={<PageNotFound/>}/>
|
|
|
+ <Route key="__notfound" path="*" element={<PageNotFound/>}/>
|
|
|
{
|
|
|
routes.map((route,index)=>{
|
|
|
- return CreateRoute({...props,route,path:route.path,isLogin:isLogin});
|
|
|
+ return CreateRoute({...props,route,path:route.path,isLogin:isLogin,key:route.path||index});
|
|
|
})
|
|
|
}
|
|
|
</Routes>
|
|
|
@@ -93,42 +89,38 @@ const CHashRouter=(props)=>{
|
|
|
}}>
|
|
|
{
|
|
|
hashs.map((item,index)=>{
|
|
|
- if (item=="")return (<></>);
|
|
|
+ if (item=="")return (<Fragment key={`empty_${index}`}/>);
|
|
|
let hash="#"+item;
|
|
|
let route=getRoutes(hash);
|
|
|
- if (route==null)return (<></>);
|
|
|
+ if (route==null)return (<Fragment key={`noroute_${index}`}/>);
|
|
|
if (!isLogin&&route.login==1){
|
|
|
//检测未登录
|
|
|
global.authLockPath=currpath;
|
|
|
navigate(pathname+currhash+route.lpath,{replace:true});
|
|
|
- return (<></>);
|
|
|
- // return (<Navigate to={pathname + currhash + route.lpath} replace={true}/>)
|
|
|
+ return (<Fragment key={`nologin_${index}`}/>);
|
|
|
}
|
|
|
//再次检查路由
|
|
|
if (!checkRoute(route.path)){
|
|
|
navigate(pathname+currhash,{replace:true});
|
|
|
- return (<></>);
|
|
|
- // return (<Navigate to={pathname+currhash} replace={true}/>)
|
|
|
+ return (<Fragment key={`badpath_${index}`}/>);
|
|
|
}
|
|
|
currhash+=hash;
|
|
|
if (route.type===ROUTE_TYPE_POP_OR_FULL)subIndex++;
|
|
|
return (
|
|
|
- // <CSSTransition timeout={timeout}>
|
|
|
- <RouteContainer level={subIndex} route={route} onClose={handleClose} header={Header[route.component]}>
|
|
|
+ <RouteContainer key={`rc_${index}`} level={subIndex} route={route} onClose={handleClose} header={Header[route.component]}>
|
|
|
<Suspense fallback={<SmallLoading/>}>
|
|
|
<Routes key={index} location={{pathname:currpath,hash:hash,search}}>
|
|
|
{
|
|
|
- routes.map((route)=>{
|
|
|
+ routes.map((route,ri)=>{
|
|
|
if (route.path===hash){
|
|
|
- return CreateRoute({...props,route,path:currpath,close:handleClose,isLogin:isLogin});
|
|
|
+ return CreateRoute({...props,route,path:currpath,close:handleClose,isLogin:isLogin,key:route.path||ri});
|
|
|
}
|
|
|
- else return (<></>);
|
|
|
+ else return (<Fragment key={`skip_${ri}`}/>);
|
|
|
})
|
|
|
}
|
|
|
</Routes>
|
|
|
</Suspense>
|
|
|
</RouteContainer>
|
|
|
- // </CSSTransition>
|
|
|
)
|
|
|
})
|
|
|
}
|