Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PathLocationStrategy vs HashLocationStrategy in web apps

Tags:

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.

like image 309
Murhaf Sousli Avatar asked Jan 10 '16 08:01

Murhaf Sousli


People also ask

What is the use of HashLocationStrategy?

HashLocationStrategylink. A LocationStrategy used to configure the Location service to represent its state in the hash fragment of the browser's URL.

What is the use of HashLocationStrategy in Angular?

HashLocationStrategy uses the hash fragment part of the URL to store state for the client, it easier to setup and doesn't require any co-operation from the server side but has the downside that it won't work with Angular Universal once that's released.

How many strategies are used to enable the location service to read route state from the browser's URL?

LocationStrategylink Enables the Location service to read route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and PathLocationStrategy .

Which Angular package is used to route to URL?

Generate an application with routing enabledlink The following command uses the Angular CLI to generate a basic Angular application with an application routing module, called AppRoutingModule , which is an NgModule where you can configure your routes.


1 Answers

# 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.

like image 193
Günter Zöchbauer Avatar answered Nov 03 '22 02:11

Günter Zöchbauer