Nasty Pirate Macaw

    react-private-route

    1.1.2 • Public • Published

    react-private-route

    npm version styled with prettier

    Declarative private routing for React

    Working demo available at

    Edit y0pw4kz8kx

    Installation

    Using npm:

    $ npm i react-private-route
    

    Using yarn:

    $ yarn add react-private-route
    

    Basic Usage

    ...
    import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
    ...
    import PrivateRoute from 'react-private-route'
    ...
     
    class App extends Component {
      render() {
        return (
         ...
            <Router>
              <div className={'main-container'}>
                <Switch>
                  <Route path="/login" component={Login} />
                  <PrivateRoute
                    exact
                    path="/"
                    component={Home}
                    isAuthenticated={!!isLoggedIn() /* this method returns true or false */}
                  />
                  <Route component={NotFound} />
                </Switch>
              </div>
            </Router>
         ...
        )
      }
    }
     
    export default App

    Issues

    If you find a bug, please file an issue on our issue tracker on GitHub.

    Credits

    React Private Route is built and maintained by @hansfpc.

    Install

    npm i react-private-route

    DownloadsWeekly Downloads

    55

    Version

    1.1.2

    License

    MIT

    Unpacked Size

    50.4 kB

    Total Files

    5

    Last publish

    Collaborators

    • hansfpc