I want to redirect to "/" , I am currently at "/register" route . If the response is ok then the page should be redirected to "/" path . I am trying to create a single page application with react js .
if(response.ok){
console.log("ok");
return redirect("/");
}
else{
console.log("error");
}
Not being redirected to the specified route .
2
Answers
assign the new location
you should be using guard clauses like such, to reduce code complexity and also make code simple and easy to read, and no if, else chain:
Gonna have to make some assumptions about the setup, but if you’re using
react-router-dom
, you can use its exporteduseNavigate
hook