1.0.4 • Published 6 years ago
privateroute v1.0.4
PrivateRoute
npm link
Restrict React Components with PrivateRoute
Installing
npm install privateroute
Usage
PrivateRoute will accept a request to the specified component represented by the specified path if the "key" variable in sessionStorage is set. Otherwise, it will redirect to the "/" page.
import PrivateRoute from 'privateroute';
// User is logged in, I will set the key as the userId
sessionStorage.setItem('key', '123')
// Will redirect to home because sesssionStorage has "key" set
<PrivateRoute path="/home" component={YOUR_REACT_COMPONENT} />