-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Using names/aliases for $routeProvider #1791
Comments
Is it not as good as using the same route definition for both aliases? Also if you're at all interested in helping the development of a future router system (such as feature requests and code contribution) you should hop on over to https://github.com/angular-ui/router |
This augments the existing $route provider so existing code will continue to work. In a view: <ul>
<li goto="home">Dashboard</li>
<li goto="profile" client="me">My Profile</li>
<li goto="profile">Grab :client from url</li>
</ul>
Routing code: angular.module('RouteExample')
.config(['$namedRouteProvider', function ($routeProvider) {
$routeProvider
.when('/', {
name: 'login',
templateUrl: 'views/login.html',
controller: 'LoginCtrl'
})
.when('/:client', {
name: 'home',
templateUrl: 'views/dashboard.html',
controller: 'DashboardCtrl'
})
.when('/:client/profile', {
name: 'profile',
templateUrl: 'views/profile.html',
controller: 'ProfileCtrl'
});
}]); |
Here is a more up-to-date version of that gist: https://github.com/cotag/ngRouteNames |
We also implemented a router that has named routes and gives ability to define language specific urls: https://github.com/sahibinden/angular-router-advanced Sorry, there is no English documentation yet, but I think example codes very self-definitive. I think named url support is a 'must' feature for big Angular applications. We also want to contribute ngRoute library if that idea is good for you. |
@btford do you have something in mind like this for the new AngularJS router? |
@matsko yes |
@IgorMinar Looking forward to it. |
Hey guys.
Keeping track of URLs and hash prefixes manually is pretty tricky and can lead to duplicate URL strings and more testing code. It would be nice if you can name your routes (optionally) and then query those names later on in your application via the
$routeProvider
service.So lets say I have a route that goes to the home page:
And my HTML links like so:
This works fine, but if I change the route to from
/home
to just/
then I need to update that.What I am proposing is that I could patch AngularJS to include support for naming and aliasing routes so that they can be accessed directly in the scope.
Then by using either a service or factory you can have access to that route:
Then you can attach this method to the
$rootScope
member and access the routes directly in the HTML (if you choose to do so).If this is OK with you guys I would happily contribute and put together the code and documentation. Is there anything in the works like this?
The text was updated successfully, but these errors were encountered: