Skip to content

Instantly share code, notes, and snippets.

@stivncastillo
Last active August 8, 2021 21:18
Show Gist options
  • Save stivncastillo/be3c699c16f8f7a02a73589c992c63f0 to your computer and use it in GitHub Desktop.
Save stivncastillo/be3c699c16f8f7a02a73589c992c63f0 to your computer and use it in GitHub Desktop.
Types routes
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