0.0.4 • Published 4 years ago
react-private-public-routes v0.0.4
react-private-public-routes
Declarative privates and public routes for React
Installation
Using npm: $ npm install react-private-public-routes
Using yarn: $ yarn add react-private-public-routes
Basic Usage
(Functional component)
import React from 'react';
import { Switch } from "react-router-dom";
import { Route } from 'react-router';
import { PrivateRoute, PublicRoute } from 'react-private-public-routes';
...
const App = props => {
...
return (
...
<Switch>
<Route path="/" component={Home} />
<PublicRoute path="/login" component={Login} auth={authToken} redirectTo="/" strict={true} exact={true} />
<PrivateRoute path="/private-dashboard" component={Dashboard} auth={authToken} redirectTo="/401" strict={true} xact={true} />
...
</Switch>
...
)
}
export default App;
(Class components)
import React, { Component } from 'react';
import { Switch } from "react-router-dom";
import { Route } from 'react-router';
import { PrivateRoute, PublicRoute } from 'react-private-public-routes';
...
class App extends Component {
...
render() {
return (
...
<Switch>
<Route path="/" component={Home} />
<PublicRoute path="/login" component={Login} auth={authToken} redirectTo="/private-dashboard" strict={true} exact={true} />
<PrivateRoute path="/private-dashboard" component={Dashboard} auth={authToken} redirectTo="/401" strict={true} xact={true} />
...
</Switch>
...
)
}
}
export default App;