react-guarded-route

1.0.5 • Public • Published

react-guarded-route

NPM JavaScript Style Guide

react-guarded-route allows you to guard your routes by a validation fuction.

Install

npm install --save react-guarded-route

Usage

import React, { Component } from 'react'
 
import GuardedRoute from 'react-guarded-route'
import { BrowserRouter, Route, Switch } from "react-router-dom";
import Dashboard from './Dashboard';
import Home from './Home';
 
const validatorFunction = () => {
  return true; //your validation logic
}
 
export default function App() {
  return(
    <Router>
        <Switch>
            <Route exact path = '/' component={Home}></Route>
            <GuardedRoute 
                path = '/dashboard'
                component = {Dashboard}
                redirectTo = '/login' //(OptionalRedirect to '/login' if validatorFunction returns falseWill redirect to '/' if not provided
                validatorFunction = {validatorFunction()}>
        </Switch>
    </Router>
  )
}

License

MIT ©

Package Sidebar

Install

npm i react-guarded-route

Weekly Downloads

2

Version

1.0.5

License

MIT

Unpacked Size

9.73 kB

Total Files

6

Last publish

Collaborators

  • aakash_varma