使用 React-Router-Dom,有没有办法在 event/function 调用上重定向页面而不是使用 <Link ... /> 并需要按下按钮?

Using React-Router-Dom, is there a way to re-direct a page on an event/function call rather than of using <Link ... /> and needing to press a button?

您好,我想知道是否可以在不使用 标签的情况下使用 react-router-dom 重定向页面?

我想在状态中的某个值达到 0 时更改页面。我想知道此操作是否可以自动执行,而不是调用 link/button 到 change/re-direct 页面?

让我知道是否需要进一步澄清此声明?

是的。在 useEffect 里面写一个函数,随着 variable.Whenever 变量的变化,useEffect 会触发并检查是否达到要求。当达到要求时。使用“useHistory”挂钩然后导航到您想要的页面。

const [value,setValue]=useState()
const history = useHistory()

useEffect(()=> {
 if (value==0) {
 history.push('/goal')
}
},[value])