how to write custom private route code example
Example 1: private routes in react
import React from 'react'
import {Route, Redirect} from 'react-router-dom'
const PrivateRoute = ({
component: Component,
isAuthenticated,
userLevel,
...rest
}) => (
<Route {...rest} component={(props)=>
isAuthenticated ? (
<Component {...props} />
):(
<Redirect to="/login" />
)
} />
)
export default PrivateRoute
Example 2: react-router-config private routes
import React from 'react'
import { Switch } from 'react-router-dom'
import renderRoutes from '../renderRoutes'
import routes from '../routes3'
const authed = false
const authPath = '/login'
const Main = () => (
<main>
<Switch>
{renderRoutes(routes, authed, authPath)}
</Switch>
</main>
)
export default Main