Skip to content

Instantly share code, notes, and snippets.

@cesar4rroyo
Last active July 13, 2020 21:50
Show Gist options
  • Save cesar4rroyo/bd14c71e7e00f0b75e1c539737df1123 to your computer and use it in GitHub Desktop.
Save cesar4rroyo/bd14c71e7e00f0b75e1c539737df1123 to your computer and use it in GitHub Desktop.
import React from "react";
import { Redirect, Route } from "react-router-dom";
import PropTypes from "prop-types";
export const PrivateRoute = ({
isAuthenticated,
component: Component,
...rest
}) => {
return (
<Route
{...rest}
component={(props) =>
isAuthenticated ? (
<Component {...props} />
) : (
<Redirect to="/login" />
)
}
></Route>
);
};
PrivateRoute.propTypes = {
isAuthenticated: PropTypes.bool.isRequired,
component: PropTypes.func.isRequired,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment