PathLocationStrategy vs HashLocationStrategy in web apps

Murhaf Sousli picture Murhaf Sousli · Jan 10, 2016 · Viewed 18.2k times · Source

What are the pros and cons of using:

  1. PathLocationStrategy - the default "HTML 5 pushState" style.
  2. HashLocationStrategy - the "hash URL" style.

for instance, using HashLocationStrategy will prevent the feature of scrolling to an element by its #ID, but some 3rd party plugins require the HashLocationStrategy or the Hashbang #! in order to work in ajax websites.

I would like to know which one offers more for a webapp.

Answer

Günter Zöchbauer picture Günter Zöchbauer · Jan 29, 2016

# can only be processed on the client, the servers just ignore them. This can cause problems with search engines (SEO), redirects can cause redundant page reloads. This page https://github.com/browserstate/history.js/wiki/Intelligent-State-Handling has some detailed explanation, while some of the arguments don't apply for Angular applications (for example - doesn't work with JS disabled).

The "disadvantage" of HTML5 pushstate is that is requires server support like explained by Thierry.