Last active
August 8, 2021 21:18
-
-
Save stivncastillo/be3c699c16f8f7a02a73589c992c63f0 to your computer and use it in GitHub Desktop.
Types routes
This file contains 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 { Redirect, Route } from "react-router-dom"; | |
export const PrivateRoute = ({ component: Component, ...rest }) => { | |
return ( | |
<Route | |
{...rest} | |
render={(props) => | |
localStorage.getItem("isAuth") === "true" ? ( | |
<Component {...props} /> | |
) : ( | |
<> | |
{alert("No tienes permitido el acceso a esta página")} | |
<Redirect | |
to={{ | |
pathname: "/", | |
state: { from: props.location }, | |
}} | |
/> | |
</> | |
) | |
} | |
></Route> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment