Why setting a prefix of $locationProvider is considered a good practice in angularjs?

101 Views Asked by At

As mentioned in Angular doc:

Setting a prefix is not necessary, but it is considered a good practice (for reasons that are outside the scope of this tutorial). ! is the most commonly used prefix.

https://docs.angularjs.org/tutorial/step_09

Do anyone know why it's a good practice? What's the advantages of using prefix?

1

There are 1 best solutions below

0
Stefano Fenu On

It should be due to the fact that the Google Ajax Crawling Scheme expects that local paths within a SPA (Single Page Application) start with a hash-bang, as you can read in the following link from the related angular feature: https://github.com/angular/angular.js/commit/aa077e81129c740041438688dff2e8d20c3d7b52

You can find more information on the Google Ajax Crawling Scheme in the following link, where they say the hash-bang (#!) is a way for the Google Crawler to understand a URL is a pretty AJAX URL:

https://developers.google.com/webmasters/ajax-crawling/docs/getting-started