urlweb-applicationsangularhashbangangular2-routing

PathLocationStrategy vs HashLocationStrategy in web apps


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.


Solution

  • For me the main difference is that the PathLocationStrategy requires a configuration on the server side to all the paths configured in @RouteConfig to be redirected to the main HTML page of your Angular2 application. Otherwise you will have some 404 errors when trying to reload your application in the browser or try to access it using a particular URL.

    Here is a question that could give you some hints about this:

    Hope it helps you, Thierry