import history from '@/utils/history'
import { hasToken } from '@//utils/storage'
import React from 'react'
import { Redirect, Route } from 'react-router-dom'

type AtahType = {
  path: string
  component: React.FC
}

export default function AuthRoute({ path, component: Com }: AtahType) {
  return (
    <Route
      path={path}
      render={() => {
        if (hasToken()) return <Com />
        else {
          alert('登录失效')
          return (
            <Redirect to={{
              pathname: '/Login',
              state: { from: history.location.pathname }
            }}
            />
          )
        }
      }}
    />
  )
}


