FrontendDeveloper.in

JavaScript question detail

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,

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

Back to all JavaScript questions
Get LinkedIn Premium at Rs 399