I'm new to React, and most of the tutorials I see about redirecting using React Router seem to be using the aforementioned snippet. What I am trying to achieve is to redirect the user to the home page of my website upon successful login. I have tried history.push but according to my google searches, it doesn't work in Router v4 anymore. What can I do as an alternative? I'm open to both stateful and stateless solutions.
To clarify, here's the workflow -
- User fills in a textbox with their username
- User fills in a textbox with their password
- User hits the submit button
- An API gets called with the username and password to authenticate the user
- The API returns success for successful login
- Upon successful login, the user is redirected to the home page