Example of a simple service (see route-urls.js) to construct application URLs from Angular's standard routing configuration.
Most of the other files in the repo are an example of how it might be used, but basically:
-
Give each route a name that is meaningful to your application, e.g.
$routeProvider.when("/product/:id/stock/:store", { name: "product:stock", ... usual stuff ... }); -
Put the
urlsservice in the root scope so it's available application-wide. -
Reference pages by name, together with any params needed to build the URL, e.g.
<a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%7B%7B+urls.href%28%27product%3Astock%27%2C+%7Bid%3A+1%2C+store%3A+%27Leeds%27%7D%29+%7D%7D"> Product 1, Leeds </a>
In the case where each named group in a route URL has a unique name and the order of the named groups is well known, paths can also be constructed by passing replacement values as positional args instead of a {name: value} map, e.g.
```
<a href="proxy.php?url=https%3A%2F%2Fgithub.com%2F%7B%7B+urls.href%28%27product%3Astock%27%2C+1%2C+%27Leeds%27%29+%7D%7D">Product 1, Leeds</a>
```