Answer the question
In order to leave comments, you need to log in
How to implement redirect in react?
There is an authorization page where the user enters a username and password. How can I automatically go to the headpage when I click the Submit button? I'm attaching the part of the code where redirect doesn't work. Is this a bug or wrong approach?
axios.post(apiBaseUrl + "account/signin", payload)
.then(function (response) {
console.log(response.data);
if(response.data.code == 200){
console.log("Login successfull");
return (<Redirect to="/Game.js" />);
Answer the question
In order to leave comments, you need to log in
such a redirect will only work in the component,
but it is better to use such an approach as a private routes
wrapper, which every time the transition will check whether the user has the right to view this page, monitoring the token in local storage
More details are described here
https://tylermcginnis.com/react -router-protected-r...
Through history.push('/home');
Details in the article "Using browser history and the redirect function ...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question