Skip to content

Instantly share code, notes, and snippets.

@binhtran04
Created November 30, 2018 19:04
Show Gist options
  • Save binhtran04/a4ace6bfbefe3077bf9e7b5f4fec7b37 to your computer and use it in GitHub Desktop.
Save binhtran04/a4ace6bfbefe3077bf9e7b5f4fec7b37 to your computer and use it in GitHub Desktop.
Public route component
import React from 'react';
import { Route, Redirect } from 'react-router-dom';
import { isLogin } from '../utils';
const PublicRoute = ({component: Component, restricted, ...rest}) => {
return (
// restricted = false meaning public route
// restricted = true meaning restricted route
<Route {...rest} render={props => (
isLogin() && restricted ?
<Redirect to="/dashboard" />
: <Component {...props} />
)} />
);
};
export default PublicRoute;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment