diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index 4000f413ecf1..ef8ef0b3cc27 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -436,6 +436,29 @@ function $RouteProvider(){ reload: function() { forceReload = true; $rootScope.$evalAsync(updateRoute); + }, + + /** + * @ngdoc method + * @name $route#parseRoute + * @return {Object} the matching route + * + * @description + * Finds the route that matches the provided path. + */ + parseRoute: function(r) { + // Match a route + var params, match; + angular.forEach(routes, function(route, path) { + if (!match && (params = switchRouteMatcher(r, route))) { + match = inherit(route, { + params: angular.extend({}, $location.search(), params), + pathParams: params}); + match.$$route = route; + } + }); + // No route matched; fallback to "otherwise" route + return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}}); } }; @@ -480,7 +503,7 @@ function $RouteProvider(){ } function updateRoute() { - var next = parseRoute(), + var next = $route.parseRoute($location.path()), last = $route.current; if (next && last && next.$$route === last.$$route @@ -554,25 +577,6 @@ function $RouteProvider(){ } } - - /** - * @returns {Object} the current active route, by matching it against the URL - */ - function parseRoute() { - // Match a route - var params, match; - angular.forEach(routes, function(route, path) { - if (!match && (params = switchRouteMatcher($location.path(), route))) { - match = inherit(route, { - params: angular.extend({}, $location.search(), params), - pathParams: params}); - match.$$route = route; - } - }); - // No route matched; fallback to "otherwise" route - return match || routes[null] && inherit(routes[null], {params: {}, pathParams:{}}); - } - /** * @returns {string} interpolation of the redirect path with the parameters */