Mostly all methods which use for web page redirection are related to window.location object, which is a property of the Window object. (For more details about Window object checkout here).
Two ways to manage the redirection of web page
window.location.href we can redirect to another web page. window.location is an object that holds the information about the current location of the document and href is property of window.location, window.location.href is full url of current page. Both works the same but differences in their usage.
window.location = "https://www.cluemediator.com/"
window.location.href = "https://www.cluemediator.com/";
If you want to redirect to internal website page use:
2. Using location object methods
Let’s start with another way to redirect to another web page using window location object.Method 1: reload()
reload() method used to refresh or reload the current page.
replace() is the method of window.location object, it will replace the current document with a new one. It rewrites the current page in history, which may affect behaviour of back button.
assign() method loads a new document in the browser window. This method different than replace() method because it rewrites the current page in history so when we click the back button, we go back to last visited page.
That’s it for today.
Thank you for reading! Happy Coding!