【问题标题】:UseHistory Hook Not workin fine?UseHistory Hook 不能正常工作?
【发布时间】:2021-12-02 10:52:33
【问题描述】:

错误

TypeError: Cannot read properties of undefined (reading 'push')

我的代码

import React from "react";

import { useHistory } from "react-router-dom";
const test = () => {
  const history = useHistory();

  function buttonPressed() {
    history.push("/sus");
  }
  return (
    <div>
      <button onClick={() => buttonPressed()}>Brn</button>
    </div>
  );
};

export default test ;

请帮助我

【问题讨论】:

标签: reactjs


【解决方案1】:

确保您的路由器已正确配置以处理对路由“/sus”的推送。

顺便说一句,你可以调用 onClick 处理程序

<button onClick={buttonPressed}>Btn</button>

【讨论】:

  • 谢谢我没有设置路由器是我的错..
  • 没问题!很高兴您解决了问题,您介意接受我的回答吗?
猜你喜欢
  • 2021-10-07
  • 2013-03-30
  • 2010-11-30
  • 2021-10-02
  • 2017-08-06
  • 2013-11-22
  • 1970-01-01
  • 2013-09-10
  • 2017-04-05
相关资源
最近更新 更多