I encountered this term in Angular JS. I know that when you enable the HTML5 mode, the Angular URLs do not have the hashtags anymore. But what is it exactly?

1 Answers

The HTML5 History API is just a handful of methods on the window.history object, plus one event on the window object that provides a way to manipulate the browser history and Angular uses this API to change the URL in the browser's location bar without triggering a page refresh.

When you enable the HTML5 mode in Angular, this uses the HTML 5 History API (history.pushState, replaceState, etc.) behind the scenes. This API allows you to manipulate the browser history through JavaScript. You can add entries to the browser history and change the URL in the browser bar (for instance, remove the hashtag from the URL) without the necessity of refreshing a page.

The HTML5 History API support is limited to the very latest versions of a few browsers. If this API is not supported by a browser, the $location service will fall back to using the hashbang (#!) URLs automatically. This is handled by the framework and is transparent to you.

From the Angular docs: Fallback for legacy browsers.. For browsers that support the HTML5 history API, $location uses the HTML5 history API to write path and search. If the history API is not supported by a browser, $location supplies a Hashbang URL. This frees you from having to worry about whether the browser viewing your app supports the history API or not; the $location service makes this transparent to you.

For more details, read this:$location#hashbang-and-html5-modes