authroute.js
723 Bytes
import React from 'react'
import { message } from 'antd'
import Storage from '@src/utils/localStorage'
import { withRouter } from 'react-router-dom'
@withRouter
class AuthRoute extends React.Component {
state = {
}
componentWillMount(){
//获取用户信息
const publicList = ['/login']
const userInfo = Storage.get('userInfo')
const { pathname } = this.props.location
if (publicList.indexOf(pathname) > -1) {
return null
}
//判断是否登录
if(!userInfo || !userInfo.token ){
// message.warn('请重新登录')
window.location.href = '#/login'
return
}
}
render() {
return <div>{this.props.children}</div>
}
}
export default AuthRoute