Skip to content

Instantly share code, notes, and snippets.

@Porter97
Created April 8, 2020 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Porter97/9b25f3e4308a49b384d8bdcdb39ee657 to your computer and use it in GitHub Desktop.
Save Porter97/9b25f3e4308a49b384d8bdcdb39ee657 to your computer and use it in GitHub Desktop.
import { Redirect, Route, withRouter } from 'react-router-dom';
import React from 'react';
const UnauthedRoute = ({ component: Component, ...rest}) => {
return(
<Route
{...rest}
render={(props) => {
if (!window.localStorage.getItem('currentUser')) {
return <Component {...props} />;
} else if (rest.redirect) {
return <Redirect to='/' />;
}
}}
/>
);
};
UnauthedRoute.defaultProps = {
redirect: true,
};
export default withRouter(UnauthedRoute)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment