Chapter 6
If we choose to use the hashbang mode we must create links as follows
(notice the # character):
<a ng-href="#/admin/users/{{user.$id()}}">Edit user</a>
While in HTML5 mode the link would be slightly simpler as follows:
<a ng-href="/admin/users/{{user.$id()}}">Edit user</a>
As you can see from the preceding examples, all the links need to be created in
accordance with the mode set on the $locationProvider service. The trouble
here is that in a typical application there are many links so if we decide to change
the configuration of $location, we will be forced to go over all the links in the
whole application and add (or remove) hashes.
Decide upon the URL mode very early in the application's
development phase, otherwise you might need to review and
change all the links in the entire application.
Linking to external pages
AngularJS assumes that links created with the a tag are internal to an application,
and as such, should change the internal state of the application, instead of triggering
a page reload in the browser. Most of the time this is the right assumption, but there
are times where we might want to provide a link pointing to a resource that should
be downloaded by the browser. In HTML5 mode it is impossible to distinguish, just
by looking at the URL links pointing to the internal state from the ones meant to
trigger a download of external resources. The solution is to use the target attribute
on such a link as follows:
<a href="/static/form.pdf" target="_self">Download</a>
Organizing route definitions
In a large scale web application, it is not uncommon to have dozens and dozens of
different routes. While the $routeProvider service offers a very nice, fluent style
API, route definitions can get quite verbose (especially when the resolve property
is used). If we combine a large number of routes with the relative verboseness of
each definition, we quickly end up maintaining a huge JavaScript file with several
hundreds of lines of code! Worse yet, having all routes defined in one huge file
means that this file must be modified quite frequently by all developers working
on a project – a recipe for creating a bottlenecks and disastrous merge issues.