Skip to content

Instantly share code, notes, and snippets.

@AlexLo33
Created July 9, 2019 08:27
Show Gist options
  • Save AlexLo33/65135d09946204594b64d1c97af4f745 to your computer and use it in GitHub Desktop.
Save AlexLo33/65135d09946204594b64d1c97af4f745 to your computer and use it in GitHub Desktop.
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
const PrivateRoute = ({ component: Component, token, ...propsRoute }) => (
<Route
{...propsRoute}
render={props => (
token !== ''
? <Component {...props} />
: (
<Redirect to={{
pathname: '/login',
state: { from: props.location },
}}
/>
)
)}
/>
);
export default PrivateRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment