InterviewHubPRO
Section Overview
Q289

Question 289 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

55%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

How do I modify the url without reloading the page

The window.location.href property will be helpful to modify the url but it reloads the page. HTML5 introduced the history.pushState() and history.replaceState() methods, which allow you to add and modify history entries, respectively. For example, you can use pushState as below,

javascript
  window.history.pushState("page2", "Title", "/page2.html");

This mechanism is used by routing libraries of frameworks like React and Angular in order to simulate the behaviour of a multi-page-website, even though they are only SPA (Single Page Applications).