Navigation
Navigation
Section titled “Navigation”Introduction
Section titled “Introduction”The location object provides methods for navigating to new URLs and reloading the page.
Navigation Methods
Section titled “Navigation Methods”// Navigate to a new page (adds to history)location.href = '/new-page'; // Same as setting location.hreflocation.assign('/new-page'); // Equivalent to setting href
// Navigate without adding to historylocation.replace('/new-page'); // Replaces current history entry
// Reloadlocation.reload(); // Reload from cachelocation.reload(true); // Force reload from server (deprecated)assign vs replace
Section titled “assign vs replace”// assign — user can go back to current pagelocation.assign('/page1');
// replace — current page is removed from history// User CANNOT go backlocation.replace('/page2');Summary
Section titled “Summary”location.href = url/location.assign(url)— navigate (adds to history)location.replace(url)— navigate (replaces history entry)location.reload()— reload current pageassignvsreplace: replace doesn’t create a back button entry