const logout = () => {
axios({
method: "GET",
url: 'http://localhost:8080/doLogout',
headers: {
Authorization: "Bearer " + localStorage.getItem("token"),
}
}).then((response) => {
alert(response.data);
})
window.localStorage.removeItem("token");
history.push('/HomePage')
}
return ( <
div >
<
div className = "container-fluid" >
<
div className = "row" >
<
div className = "col-sm-5 col-md-4 col-lg-4" >
<
/div> <
div className = "col-sm-2 col-md-4 col-lg-3" >
<
button type = "button"
className = "btn btn-primary btn-lg"
onClick = {
() => logout()
} >
Logout < /button> <
/div> <
div className = "col-sm-5 col-md-4 col-lg-5" >
<
/div> <
/div> <
/div> <
/div>
);
}
我正在尝试通过使用history.push方法将用户单击按钮重定向到主页。任何人都可以告诉我正确的方法来重定向用户。我也尝试了从React Router重定向方法,但这似乎也不起作用] >
const logout =()=> {axios({方法:“ GET”,URL:'http:// localhost:8080 / doLogout',标头:{授权:“ Bearer” + localStorage.getItem(“ token”) ,...