PrivateRoute.js 429 Bytes
Newer Older
CHAERIN KIM's avatar
CHAERIN KIM committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import React from 'react';
import { Redirect, Route } from "react-router-dom";

export const PrivateRoute = ({ component: Component, ...rest }) => (
  <Route
    {...rest}
    render={props =>
      (localStorage.getItem("token") !==null) ? (
        <Component {...props} />
      ) : (
          <Redirect to={{ 
            pathname: "/login",
            state: {match: props.location}
           }} />
        )
    }
  />
)