当用户单击Reactjs中的警报框时,如何将用户重定向到另一个页面

问题描述 投票:0回答:1
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”) ,...

reactjs click alert
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.