'How do I use history.push("/") conditionitionaly depending on the page you are?

I am using history.push("/") on the login page when login is successful. This is when I directly go to login page. I also want to redirect to login page on the checkout page is the user in not logged in. Then after that I want the user to go on next page not on homepage ("/"). How do I can do this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source