可以尝试以下解决方法:
import { BrowserRouter as Router, Route } from 'react-router-dom';
function App() {
return (
);
}
import { Link, useHistory } from 'react-router-dom';
function MyButton() {
const history = useHistory();
const handleClick = () => {
history.push('/about');
};
return (
);
}
function App() {
return (
About
);
}
import { useHistory } from 'react-router-dom';
function MyButton() {
const history = useHistory();
const handleClick = () => {
history.push('/about');
};
return (
);
}
function App() {
return (
About
);
}
通过以上方法,你可以解决按钮点击时React路由器不起作用的问题。
上一篇:按钮点击时重复调用Ajax请求