reactjs - 如何使用 React 中的 onScroll 事件使用 React-Router 移动到另一个页面
问题描述
我目前在 React 中有一个英雄图像组件,当用户尝试向下滚动页面时,我想移动到购物页面,就好像它们已连接,而实际上它们没有连接。这将使我的其他导航更容易,同时仍然保持所有组件和路线分开。
class Home extends Component {
constructor(props) {
super(props);
this.handleScroll = this.handleScroll.bind(this);
}
handleScroll() {
let history = useHistory();
history.push('/categories');
console.log('done');
}
render() {
return (
<Hero onScroll={this.handleScroll}>
我的 console.log 永远不会被执行。
解决方案
让我们用onWheel改变onScroll
<Hero onWheel={this.handleScroll}>
推荐阅读
- windows-10 - Spyder IDE 无法在带有 Python 3.8 的 Windows 10 上启动
- c# - C# 连接到 web 服务
- c# - Visual Studio 安装程序错误与 Visual C++ 2017 运行时库 (x64) 先决条件
- c++ - C ++中的动态长度数组
- php - 如何在代码点火器中调试存储过程查询?
- vue.js - Vuejs 简化了 Vuex 动作调用
- jenkins - Jenkins 作业 dsl 使用“plugin=”配置块
- css - 查询生成器容器覆盖了角度自动完成
- java - 本地主机时如何重定向到本地存储的 index.html 文件:
从浏览器调用 - python - 如何从Django中的另一个视图继承