I defined some routes:
angular.module('myApp', [])
.config('$routeProvider', function($routeProvider) {
$routeProvider.when('/aaa', { templateUrl: '/111.html' })
.when('/bbb', { templateUrl: '/222.html'});
});
And I want to get the route name when user changes the route:
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: ' + ???);
}
}]);
But I don't know how to get it. I can get the templateUrl
, but not the route name.
UPDATE
A more complex use case:
$routeProvider.when('/users/:id', { templateUrl: '/show_user.html' })
If current path is:
/users/12345
It should match /users/:id
, but how do I know which route is matched and to get the route name /users/:id
?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…