0.0.4 • Published 4 years ago

react-private-public-routes v0.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
4 years ago

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;
0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago