Skip to content

Instantly share code, notes, and snippets.

@binhtran04
Created November 30, 2018 19:01
Show Gist options
  • Save binhtran04/31909eef58e15ecdc379ec07e9753c01 to your computer and use it in GitHub Desktop.
Save binhtran04/31909eef58e15ecdc379ec07e9753c01 to your computer and use it in GitHub Desktop.
Private route component
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { isLogin } from '../utils';
const PrivateRoute = ({component: Component, ...rest}) => {
return (
// Show the component only when the user is logged in
// Otherwise, redirect the user to /signin page
<Route {...rest} render={props => (
isLogin() ?
<Component {...props} />
: <Redirect to="/signin" />
)} />
);
};
export default PrivateRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment