Created
May 26, 2020 14:26
-
-
Save danileao/2671fdff5131a60a0eb1124cb375f3e5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from "react"; | |
import { | |
Route, | |
Redirect, | |
RouteComponentProps, | |
RouteProps, | |
} from "react-router-dom"; | |
import AuthLayout from "../pages/_layouts/auth"; | |
import DefaultLayout from "../pages/_layouts/default"; | |
interface IRouteProps extends RouteProps { | |
isPrivate?: boolean; | |
component: React.ComponentType; | |
} | |
const RouteWrapper: React.FC<IRouteProps> = ({ | |
component: Component, | |
isPrivate = false, | |
...rest | |
}) => { | |
const signed = true; | |
if (!signed && isPrivate) { | |
return <Redirect to="/" />; | |
} | |
if (signed && !isPrivate) { | |
return <Redirect to="/artists" />; | |
} | |
const Layout = signed ? DefaultLayout : AuthLayout; | |
return ( | |
<Route | |
{...rest} | |
render={(props: RouteProps) => ( | |
<Layout> | |
<Component {...props} /> | |
</Layout> | |
)} | |
/> | |
); | |
}; | |
export default RouteWrapper; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment