Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why we need bang mark in hash navigation URLs?

We are developing SPA with hash tag navigation. Saw on another SPA sites there is hash tag URLs like http://example.com/#!/users Our application currently implements hash tag URLS without ! (bang, exclamation mark) like http://example.com/#/users Is there some reason for using bang mark in URL? I've checked few SO questions, some documentation: URL hash-bang (#!/) prefix instead of simple hash (#/) in Angular 1.6 People want to get rid of exclamation mark in their SPAs.

However, Angular Changelog states it was significant change to add bang mark in URLs: https://github.com/angular/angular.js/blob/master/CHANGELOG.md#location-due-to

Google's documentation also shows an examples with exclamation marks: https://developers.google.com/webmasters/ajax-crawling/docs/getting-started

My main question is - for what we need exclamation mark in hash URL? Does it makes any sense?

Thanks in advance for answers!

like image 885
Serj.by Avatar asked Sep 27 '17 07:09

Serj.by


People also ask

Can I have exclamation mark in URL?

According to RFC 1738, an exclamation mark is a valid character: Thus, only alphanumerics, the special characters “$-_. +!* '(),”, and reserved characters used for their reserved purposes may be used unencoded within a URL.

How do I know if a URL has a hash?

The task is to check whether an URL contains or not. This can be done by using the Location hash property in JavaScript. It returns the string which represents the anchor part of a URL including the hash '#' sign.

How do I get hash character out of URL?

Replace the hash with %23 . # is a valid URI character, but it starts the hash fragment, so you need to encode it in the query string. Compare encodeURIComponent('#') .


1 Answers

RFC 3986 specifies that a URL fragment starts with a hash. A fragment references typically a HTML anchor. And HTML 4 defines that the ID of a HTML anchor must not contain a bang.

If you want to be sure that your tags do not collide with HTML anchors, it might be useful to mark the tags with the bang.

like image 122
ceving Avatar answered Oct 05 '22 16:10

ceving