Categories
JavaScript Answers

How to remove hash from URL with JavaScript?

Spread the love

Sometimes, we want to remove hash from URL with JavaScript.

In this article, we’ll look at how to remove hash from URL with JavaScript.

How to remove hash from URL with JavaScript?

To remove hash from URL with JavaScript, we call the history.pushState method.

For instance, we write

history.pushState("", document.title, window.location.pathname);

to call pushState with '' and window.location.pathname to remove the hash from the URL.

Conclusion

To remove hash from URL with JavaScript, we call the history.pushState method.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

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