README
react-guarded-route
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' //(Optional) Redirect to '/login' if validatorFunction returns false. Will redirect to '/' if not provided.
validatorFunction = {validatorFunction()}>
</Switch>
</Router>
)
}