首页 > 解决方案 > 我如何在函数反应 js 中转到另一个页面

问题描述

我是 React js 的新手,我想在成功登录 react js 后转到主页。现在我有这个功能在反应,我正在用它回家。

  handleClick(e) {

    const tok = this.state.username + ':' + this.state.password;
    const hash = Base64.encode(tok);
    const Basic = 'Basic ' + hash;

   
    const history = createHashHistory();

    Axios.get(ServiceName.BaseUrl + '/auth/login', {withCredentials: true, headers: {'Authorization': Basic}})
        .then(res => {

            if (res.status == 200) {
           /*go to page : "/home"*/
            }

        })
        .catch(err => {
            console.log(err);
           
        });

}

或重定向

标签: javascriptreactjsfunctionauthenticationredirect

解决方案


您可以简单地:

history.push('/home')

推荐阅读