npm

Need private packages and team management tools?Check out npm Orgs. »

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

346

version

1.1.2

license

MIT

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability