Skip to content

Instantly share code, notes, and snippets.

@docentedev
Last active December 7, 2019 00:01
Show Gist options
  • Save docentedev/cc74dd18d65172594211a52dcf0ff6c8 to your computer and use it in GitHub Desktop.
Save docentedev/cc74dd18d65172594211a52dcf0ff6c8 to your computer and use it in GitHub Desktop.
import React from 'react';
import { Redirect, Route } from 'react-router-dom';
import { isLogin } from '../../utils/session';
export const PrivateRoute = ({ component: Component, ...rest}) => (
<Route
{...rest}
render={props =>
isLogin() ? (
<Component {...props} />
) : (
<Redirect
to={{
pathname: '/',
state: { from: props.location }
}}
/>
)
}
/>
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment