layout-dmoli2
v1.0.1
Published
A Private Route component on top of React and react-router
Downloads
21
Maintainers
Readme
react-private-route
Declarative private routing for React
Working demo available at
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.