javascript - 我如何在函数反应 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);
});
}
或重定向
解决方案
您可以简单地:
history.push('/home')
推荐阅读
- qt - 如何在 QProcess 中使用 cmd.exe 命令
- python - 为什么 plotly express 会在时间线上抛出数据点?
- php - 在 cakephp 2 中创建 shell 的问题
- javascript - jQuery - 在所有项目上运行 keyup 函数
- java - 来自在 Oracle Database 12.2 中运行的 Java 存储过程的 JDBC 连接不起作用
- android - 更改字符串列表的颜色 - Flutter
- php - 使用翻译在 Laravel 中进行网站翻译
- node.js - MongoDb Aggregation - 如何获取 $count 以及其他属性?
- wordpress - 如何将 apache2 链接到 wordpress docker 容器?
- javascript - 我如何创建一个菜单,用户可以在其中插入和删除认为他/她添加的内容?在 Eclipse 中的 javascript google-appengine