|
|
@@ -1,7 +1,11 @@
|
|
|
import AllComponents from '@pages/index';
|
|
|
-import {Route, Routes} from 'react-router-dom';
|
|
|
-import {lazy, Suspense} from "react";
|
|
|
+import {Route, Routes, useNavigate} from 'react-router-dom';
|
|
|
+import React, {cloneElement, lazy, Suspense} from "react";
|
|
|
import SmallLoading from "@components/SmallLoading";
|
|
|
+import TransitionGroup from "react-transition-group/TransitionGroup";
|
|
|
+import CSSTransition from "react-transition-group/CSSTransition";
|
|
|
+import SubScreen from "@components/SubScreen";
|
|
|
+import RouteContainer from "@layout/Routes/RouteContainer";
|
|
|
const RouteWrapper = lazy(() => import('@layout/Routes/RouteWrapper'));
|
|
|
|
|
|
const PageNotFound = lazy(() => import('@pages/PageNotFound'));
|
|
|
@@ -42,47 +46,58 @@ const CBrowserRouter=(props)=>{
|
|
|
}
|
|
|
const CHashRouter=(props)=>{
|
|
|
const {routes,hlocation}=props;
|
|
|
+ const navigate = useNavigate()
|
|
|
//多hash 切到最后一个
|
|
|
let {pathname,hash,search}=hlocation;
|
|
|
let paths=pathname.split("#");
|
|
|
pathname=paths.shift();
|
|
|
let hashs=hash.split("#");
|
|
|
- // hash="#"+hashs.pop();
|
|
|
- // pathname=pathname+hash;
|
|
|
- // console.log({pathname,hash,search})
|
|
|
let currpath=pathname+hash;
|
|
|
- // let currhash="";
|
|
|
+ const timeout=200;
|
|
|
//多hash 切到最后一个
|
|
|
+ const getRoutes=(path)=>{
|
|
|
+ for (const route of routes) {
|
|
|
+ if (route.path===path)return route;
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ const handleClose = () => {
|
|
|
+ navigate(-1);
|
|
|
+ }
|
|
|
return (
|
|
|
- <>
|
|
|
+ <TransitionGroup
|
|
|
+ className="app-hash"
|
|
|
+ childFactory={child => {
|
|
|
+ let isopen=child.props.in;
|
|
|
+ return cloneElement(child, {open:isopen})
|
|
|
+ }}>
|
|
|
{
|
|
|
hashs.map((item,index)=>{
|
|
|
if (item=="")return (<></>);
|
|
|
let hash="#"+item;
|
|
|
+ let route=getRoutes(hash);
|
|
|
+ if (route==null)return (<></>);
|
|
|
return (
|
|
|
- <Suspense fallback={<SmallLoading></SmallLoading>}>
|
|
|
- <Routes key={index} location={{pathname:currpath,hash:hash,search}}>
|
|
|
- {
|
|
|
- routes.map((route)=>{
|
|
|
- if (route.path===hash){
|
|
|
- return createRoute({...props,route,path:currpath});
|
|
|
+ <CSSTransition timeout={timeout}>
|
|
|
+ <RouteContainer route={route} timeout={timeout} onClose={handleClose}>
|
|
|
+ <Suspense fallback={<SmallLoading/>}>
|
|
|
+ <Routes key={index} location={{pathname:currpath,hash:hash,search}}>
|
|
|
+ {
|
|
|
+ routes.map((route)=>{
|
|
|
+ if (route.path===hash){
|
|
|
+ return createRoute({...props,route,path:currpath,close:handleClose});
|
|
|
+ }
|
|
|
+ else return (<></>);
|
|
|
+ })
|
|
|
}
|
|
|
- else return (<></>);
|
|
|
- })
|
|
|
- }
|
|
|
- </Routes>
|
|
|
- </Suspense>
|
|
|
+ </Routes>
|
|
|
+ </Suspense>
|
|
|
+ </RouteContainer>
|
|
|
+ </CSSTransition>
|
|
|
)
|
|
|
})
|
|
|
}
|
|
|
- </>
|
|
|
- // <Routes location={{pathname,hash,search}}>
|
|
|
- // {
|
|
|
- // routes.map((route,index)=>{
|
|
|
- // return createRoute({...props,route});
|
|
|
- // })
|
|
|
- // }
|
|
|
- // </Routes>
|
|
|
+ </TransitionGroup>
|
|
|
)
|
|
|
}
|
|
|
export {CBrowserRouter,CHashRouter};
|