Reinit project
This commit is contained in:
31
src/pages/routes.tsx
Normal file
31
src/pages/routes.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
import React, { useEffect } from 'react';
|
||||
import { Redirect, RouterTypes } from 'umi'
|
||||
import { connect } from 'dva';
|
||||
import { UserModelState } from '@/models/user';
|
||||
|
||||
import styles from './index.css';
|
||||
|
||||
const unauthorizedPaths = [
|
||||
'/check',
|
||||
'/register',
|
||||
];
|
||||
|
||||
const Page: React.FC<RouterTypes & UserModelState> = ({
|
||||
isLogin,
|
||||
children,
|
||||
location: { pathname },
|
||||
}) => {
|
||||
if (pathname !== '/' && !isLogin && !unauthorizedPaths.includes(pathname)) {
|
||||
return <Redirect to="/check" />
|
||||
}
|
||||
if (isLogin && unauthorizedPaths.includes(pathname)) {
|
||||
return <Redirect to="/home" />;
|
||||
}
|
||||
return (
|
||||
<>{children}</>
|
||||
);
|
||||
};
|
||||
|
||||
export default connect(
|
||||
({ user }: any) => ({ ...user }),
|
||||
)(Page);
|
||||
Reference in New Issue
Block a user