Skip to content

atomatt/angular-route-urls

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

angular-route-urls

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:

  1. Give each route a name that is meaningful to your application, e.g.

    $routeProvider.when("/product/:id/stock/:store", {
        name: "product:stock",
        ... usual stuff ...
    });
    
  2. Put the urls service in the root scope so it's available application-wide.

  3. 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>
```

About

Angular service to construct application URLs from routing configuration.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors