diff options
author | eug-vs <eug-vs@keemail.me> | 2020-08-07 22:25:20 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-08-07 22:25:20 +0300 |
commit | 2d6ba7459fff67823b55cfc39342896873962714 (patch) | |
tree | abdbe2503cc9a08226175cac1fad0e09eed698be /src/pages/PrivateRoute.tsx | |
parent | 056ef91e36f86a3278dfbb2f369939534bffe7e2 (diff) | |
download | which-ui-2d6ba7459fff67823b55cfc39342896873962714.tar.gz |
refactor: simplify Route component
Diffstat (limited to 'src/pages/PrivateRoute.tsx')
-rw-r--r-- | src/pages/PrivateRoute.tsx | 29 |
1 files changed, 0 insertions, 29 deletions
diff --git a/src/pages/PrivateRoute.tsx b/src/pages/PrivateRoute.tsx deleted file mode 100644 index 685e53d..0000000 --- a/src/pages/PrivateRoute.tsx +++ /dev/null @@ -1,29 +0,0 @@ -import React from 'react'; -import { Redirect, Route } from 'react-router-dom'; -import { useAuth } from '../hooks/useAuth'; -import urls from './urls'; - - -const PrivateRoute: React.FC<any> = ({ component: ProtectedComponent, ...rest }) => { - const { isAuthenticated } = useAuth(); - - const getComponent: React.FC<any> = (props) => { - if (props.match.path === urls.login || props.match.path === urls.registration) { - return isAuthenticated() ? ( - <Redirect to={urls.profile} /> - ) : ( - <ProtectedComponent {...props} /> - ); - } - - return isAuthenticated() ? ( - <ProtectedComponent {...props} /> - ) : ( - <Redirect to={{ pathname: urls.login, state: { from: props.location } }} /> - ); - } - - return <Route {...rest} render={getComponent} />; -}; - -export default PrivateRoute; |