【发布时间】:2013-03-12 05:59:17
【问题描述】:
我定义了一些路线:
angular.module('myApp', [])
.config('$routeProvider', function($routeProvider) {
$routeProvider.when('/aaa', { templateUrl: '/111.html' })
.when('/bbb', { templateUrl: '/222.html'});
});
并且我想在用户更改路线时获取路线名称:
angular.module('myApp')
.run(['$rootScope', function($rootScope) {
$rootScope.$on('$routeChangeSuccess', function(scope, current, pre) {
// how to get current route name, e.g. /aaa or /bbb
console.log('Current route name: ' + ???);
}
}]);
但我不知道如何获得它。我可以得到templateUrl,但不能得到路由名称。
更新
一个更复杂的用例:
$routeProvider.when('/users/:id', { templateUrl: '/show_user.html' })
如果当前路径是:
/users/12345
它应该匹配/users/:id,但是我如何知道匹配哪个路由并获取路由名称/users/:id?
【问题讨论】:
标签: angularjs