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.
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 .
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 })
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.