-2

I'm a newbie in js, I follow this example to study how to route UI in SPA with angularjs.
When I download and run this example, the URL is

"http://localhost:8080/#/home" 

but when I start to create my sample myself, the URL always is

"http://localhost:8080/#!/home"

I don't know the meaning of "!" symbol in the URL. My sample still work but the "!" inside the URL make me confuse, I wonder that "something was missing, isn't it?" Please teach me or give me some keywords to understand the problem deeper. Thanks

Animay
  • 602
  • 1
  • 7
  • 18
Vincent
  • 21
  • 5
  • 1
    it's called hashbang mode (`#`-hash, `!`-bang). it's documented and discussed in detail in the documentation at https://docs.angularjs.org/guide/$location#hashbang-mode-default-mode- – Claies Apr 05 '18 at 06:59
  • 1
    Possible duplicate of [what is the # symbol in the url](https://stackoverflow.com/questions/7909969/what-is-the-symbol-in-the-url) – Ramesh Rajendran Apr 05 '18 at 06:59
  • 1
    https://www.w3schools.com/HTML/html_links.asp https://en.wikipedia.org/wiki/Fragment_identifier – Parth Raval Apr 05 '18 at 07:01
  • 1
    With AngularJS V1.6, the default hash-prefix used for `$location` hash-bang URLs has changed from the empty string `('')` to the bang `('!')`. For more information, see [AngularJS Developer Guide - Migrating to V1.6 - `$location`](https://docs.angularjs.org/guide/migration#-location-). – georgeawg Apr 05 '18 at 10:13

1 Answers1

3

It is called Fragment_identifier


The $location service is designed to support hash prefixed URLs for cases where the browser does not support HTML5 push-state navigation.

The Google Ajax Crawling Scheme expects that local paths within a SPA start with a hash-bang (e.g. somedomain.com/base/path/#!/client/side/path).

The $locationProvide allows the application developer to configure the hashPrefix, and it is normal to set this to a bang '!', but the default has always been the empty string ''.

This has caused some confusion where a user is not aware of this feature and wonders why adding a hash value to the location (e.g. $location.hash('xxx')) results in a double hash: ##xxx.

This commit changes the default value of the prefix to '!', which is more natural and expected.

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

Referred from

and please visit here : URL hash-bang (#!/) prefix instead of simple hash (#/) in Angular 1.6

Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234
  • Thank you for your clear explanation, and reference. Now I understand the symbol's meaning. I will spend more time in $locationProvider and $location too. btw, a small question (I think it relates to my op), as you said "The $locationProvide allows the application developer to configure the hashPrefix, and it is normal to set this to a bang '!', but the default has always been the empty string ''. I don't know the use case of config the hashPrefix, atm I think that we can use the default hashbang instead of config it to hash, can you give me some hint? – Vincent Apr 05 '18 at 07:32
  • 1
    With AngularJS V1.6, the default hash-prefix used for `$location` hash-bang URLs has changed from the empty string `('')` to the bang `('!')`. For more information, see [AngularJS Developer Guide - Migrating to V1.6 - `$location`](https://docs.angularjs.org/guide/migration#-location-). – georgeawg Apr 05 '18 at 10:15