The location method mimics the user behavior of typing a URL address in the address bar of the browser window. The browser then forwards to that web site, leaving the last web page in the previous entry of browsing history.
The second approach is to use the replace method of location object:
This is trickier in that it’s not like what users would do. Instead of creating a new history entry, this method replaces the old history entry by the new one. Essentially, users cannot go back to the previous page with this approach, the previous web page is replaced by the new one: http://www.microsoft.com.
You should also read:
- How to redirect the visitor to another page or website?
- Redirect 404 Error to Home Page