|
|
@@ -6,46 +6,53 @@ 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";
|
|
|
+import {Navigate, useLocation} from "react-router";
|
|
|
+import usePreviousRoute from "@hooks/usePreviousRoute";
|
|
|
const RouteWrapper = lazy(() => import('@layout/Routes/RouteWrapper'));
|
|
|
|
|
|
const PageNotFound = lazy(() => import('@pages/PageNotFound'));
|
|
|
|
|
|
-const createRoute=(props)=>{
|
|
|
- const {route,path}=props;
|
|
|
+const CreateRoute=(props)=>{
|
|
|
+ const {route,path,isLogin}=props;
|
|
|
const component=(route.component!=null&&route.component!=="")?route.component:"ModulePage";
|
|
|
const Component = AllComponents[component];
|
|
|
const checkLogin=()=>{
|
|
|
+ if (!isLogin&&route.login===1){
|
|
|
+ return (<Navigate to={route.lpath} replace={true}></Navigate>)
|
|
|
+ }
|
|
|
return (
|
|
|
<RouteWrapper {...{ ...props, Comp: Component, route: route }} />
|
|
|
)
|
|
|
}
|
|
|
return (
|
|
|
- <Route
|
|
|
- key={route.path}
|
|
|
- exact
|
|
|
- path={path?path:route.path}
|
|
|
- element={checkLogin()}
|
|
|
- >
|
|
|
+ <>
|
|
|
+ <Route
|
|
|
+ key={route.path}
|
|
|
+ exact
|
|
|
+ path={path?path:route.path}
|
|
|
+ element={checkLogin()}
|
|
|
+ >
|
|
|
|
|
|
- </Route>
|
|
|
+ </Route>
|
|
|
+ </>
|
|
|
)
|
|
|
}
|
|
|
|
|
|
const CBrowserRouter=(props)=>{
|
|
|
- const {routes}=props;
|
|
|
+ const {routes,isLogin}=props;
|
|
|
return (
|
|
|
<Routes>
|
|
|
<Route path="*" element={<PageNotFound/>}/>
|
|
|
{
|
|
|
routes.map((route,index)=>{
|
|
|
- return createRoute({...props,route,path:route.path});
|
|
|
+ return CreateRoute({...props,route,path:route.path,isLogin:isLogin});
|
|
|
})
|
|
|
}
|
|
|
</Routes>
|
|
|
)
|
|
|
}
|
|
|
const CHashRouter=(props)=>{
|
|
|
- const {routes,hlocation}=props;
|
|
|
+ const {routes,hlocation,isLogin}=props;
|
|
|
const navigate = useNavigate()
|
|
|
//多hash 切到最后一个
|
|
|
let {pathname,hash,search}=hlocation;
|
|
|
@@ -77,6 +84,11 @@ const CHashRouter=(props)=>{
|
|
|
let hash="#"+item;
|
|
|
let route=getRoutes(hash);
|
|
|
if (route==null)return (<></>);
|
|
|
+ if (!isLogin&&route.login==1){
|
|
|
+ //检测未登录
|
|
|
+ navigate(route.lpath,{replace:true});
|
|
|
+ return (<></>);
|
|
|
+ }
|
|
|
return (
|
|
|
<CSSTransition timeout={timeout}>
|
|
|
<RouteContainer route={route} timeout={timeout} onClose={handleClose}>
|
|
|
@@ -85,7 +97,7 @@ const CHashRouter=(props)=>{
|
|
|
{
|
|
|
routes.map((route)=>{
|
|
|
if (route.path===hash){
|
|
|
- return createRoute({...props,route,path:currpath,close:handleClose});
|
|
|
+ return CreateRoute({...props,route,path:currpath,close:handleClose,isLogin:isLogin});
|
|
|
}
|
|
|
else return (<></>);
|
|
|
})
|