[英]Detect the url of redirection in React Router v6
I am using React v6, and I want to have a button that redirects the user to the page which redirected him to the current page.我正在使用 React v6,我想要一个按钮,将用户重定向到将他重定向到当前页面的页面。
And I know this question may hold two different questions, so here's what's exactly the question is focusing on:而且我知道这个问题可能包含两个不同的问题,所以这就是问题的重点:
I couldn't find a clean way to do so using react v6, all the other answers are showing solutions using obsolete and extremely old versions of react-router-dom .我找不到使用 react v6 的干净方法,所有其他答案都显示了使用过时和极其旧版本的react-router-dom的解决方案。
Isn't it an option just to use something like that?只是使用类似的东西不是一种选择吗?
const navigate = useNavigate();
...
navigate(-1);
i am not sure if you want to do something in the page from where you are redirecting.我不确定您是否想在您重定向的页面中执行某些操作。 if you want to redirect instantly you can do the following
如果您想立即重定向,您可以执行以下操作
const navigate = useNavigate()
...
// when clicked on button
const handleClick = () => {
navigate("redirect")
navigate("current url", { replace: true })
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.