Skip to content

Instantly share code, notes, and snippets.

@cesar4rroyo
Last active July 13, 2020 21:47
Show Gist options
  • Save cesar4rroyo/874ee2c162cf472b925715cdd664acd7 to your computer and use it in GitHub Desktop.
Save cesar4rroyo/874ee2c162cf472b925715cdd664acd7 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 PublicRoute = ({
isAuthenticated,
component: Component,
...rest
}) => {
return (
<Route
{...rest}
component={(props) =>
!isAuthenticated ? (
<Component {...props} />
) : (
<Redirect to="/" />
)
}
></Route>
);
};
PublicRoute.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