Skip to main content
InterviewHubPRO
Section Overview
Q289

Question 289 of 536

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

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

How do I modify the url without reloading the page

mid LevelCode ExamplejavascriptES6+ Modern Syntax

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).