错误
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 ;
请帮帮我
确保你的路由器配置正确,以处理推送到路由"/sus"
顺便说一下,你可以用 调用onClick处理程序<button onClick={buttonPressed}>Btn</button>