gpt4 book ai didi

javascript - react-router-dom v6 中的 history.replace

转载 作者:行者123 更新时间:2023-12-05 00:25:14 24 4
gpt4 key购买 nike

我以前用过react-router-dom v5.2.0 .那里我用了history.replace('/path)将页面重定向到另一个页面。 (因此它不会存储在地址历史记录中)。现在我必须使用 react-router-dom v6.0.0-beta.0 .在版本 6 中,我必须使用 useNavigate Hook 而不是 useHistory钩。我可以如下使用它。

const navigate = useNavigate();
navigate('/path')
但我不知道如何使用它进行重定向。 (如 history.replace )

最佳答案

如果您需要替换当前位置而不是将新位置推送到历史堆栈,请使用 navigate(to, { replace: true }) .如果需要状态,请使用 navigate(to, { state }) .

关于javascript - react-router-dom v6 中的 history.replace,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68694012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com