by @saigowthamr

How to redirect to another Webpage in JavaScript

Home » javascript » How to redirect to another Webpage in JavaScript

This example will show you how to redirect to another webpage in JavaScript by using location.replace and location.href.

// it stimulates HTTP redirect
window.location.replace("https://reactgo.com");

// it stimulates mouse click on a link
window.location.href = "https://reactgo.com";

The main difference between location.replace and location.href is replace() removes the URL history from a document and href doesn’t remove the history so that we can go back to the previously visited page.