react-protected-route

1.0.8 • Public • Published

react-protected-route

npm version Build Status NPM Packages NPM Dev Dependencies

A ReactJS route component that redirects users trying to access a protected route.

Example

The code below assumes isAuthenticated is true, and will render the protected route.

import ProtectedRoute from "react-protected-route";
 
// this can be read from your state which looks at 
// login and/or any logic to protect certain routes.
const isLoggedIn = false; 
 
// Example usage
const Routes = () => 
<Switch>
    <ProtectedRoute
        isAuthenticated={isLoggedIn}
        redirectTo="/login"
        path="/myaccount"
        component={() => <p>Protected account access</p>}
    />
    <Route
        path="/login"
        render={() => <p>Please sign in to access your account.</p>}
    />
</Switch>;

Package Sidebar

Install

npm i react-protected-route

Weekly Downloads

1

Version

1.0.8

License

ISC

Unpacked Size

40.2 kB

Total Files

14

Last publish

Collaborators

  • devbytecom