我有这个注销功能:
logOut = () => { axios .delete(`${apiUrl}/logout`) .then(response => { if (response.status === 204) { localStorage.removeItem('key', response.headers.authorization) localStorage.removeItem('id', response.data.id) // return <Redirect to="/login" /> this.props.history.push(`/login`) } }) .catch(error => { console.log(error) }) }
this.props.history.push('/something') 在其他场合都有用。但这里写的是不识字 push 未定义的。我试过了 return <Redirect to="/login" /> 这也不管用。
this.props.history.push('/something')
push
return <Redirect to="/login" />
我做错什么了?
可能是因为以下原因之一:
import { withRouter } from 'react-router-dom // ... codes of component in here ... export default withRouter(componentName) // at the end of component
这
var that = this; // then use that in axios