// 该组件用于判断有无登录
import React from 'react';
import { Redirect, withRouter } from 'react-router-dom';
import Main from '../modules/main';
import { getItem } from '../utils';

const CheckLogin = withRouter(props => {
  const { children, location } = props;
  const isLogin = getItem('token');
  return isLogin ? <Main>{children}</Main> : <Redirect to={{ pathname: '/login', state: { from: location } }} />;
});

export default CheckLogin;
