PrivateRoute.js 370 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import React from 'react'
import { Redirect, Route } from 'react-router-dom'
import { isAuthenticated } from '../utils/auth'

function PrivateRoute({ path, children }) {
  if (isAuthenticated()) {
    return (
      <Route path={path}>
        {children}
      </Route>
    )
  } else {
    return (
     <Redirect to='/login'/>
    )
  }

}

export default PrivateRoute