注入$location服务,使用path()方法获取路由状态和路由参数
angular.module('myApp')
.run(['$rootScope', '$location', '$routeParams', function($rootScope, $location, $routeParams) {
$rootScope.$on('$routeChangeSuccess', function(e, current, pre) {
//获取路由状态
console.log('Current route name: ' + $location.path());
// 获取路由参数
console.log($routeParams);
});
}]);