I have seen many methods like
) is better than using window.location.href
.replace() does not keep the originating page in the session history, meaning the user won't get stuck in a never-ending back-button fiasco, as it simulates an HTTP redirect
windows.location.href provides similar behavior as clicking on a link.
If you want to simulate someone clicking on a link, use
If you want to simulate an HTTP redirect, use
// similar behavior as an HTTP redirect window.location.replace("http://example.com"); // similar behavior as clicking on a link window.location.href = "http://example.com";
Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly