How to update the page title when using history.replaceState() with JavaScript?

Spread the love

Sometimes, we want to update the page title when using history.replaceState() with JavaScript.

In this article, we’ll look at how to update the page title when using history.replaceState() with JavaScript.

How to update the page title when using history.replaceState() with JavaScript?

To update the page title when using history.replaceState() with JavaScript, we set the title manually.

For instance, we write

document.title = "bar";
window.history.pushState({}, "bar", "/bar");

to set the page title to 'bar' with

document.title = "bar";

Then we use pushState to navigate to '/bar'.

Conclusion

To update the page title when using history.replaceState() with JavaScript, we set the title manually.

Leave a Reply

Your email address will not be published. Required fields are marked *