Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Made the route matcher public, allows to parse inputs from the url #1234

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 27 additions & 20 deletions src/ng/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,32 @@ function $RouteProvider(){
reload: function() {
forceReload = true;
$rootScope.$evalAsync(updateRoute);
},

/**
* @ngdoc method
* @name ng.$route#match
* @methodOf ng.$route
*
* @description
* Tries to match a URL path with a set of routes.
*
* @param {LocationUrl} location The path info to be parsed
* @returns {Object} route Mapping information
*/
match: function(location) {
// Match a route
var params, match = null;
forEach(this.routes, function(route, path) {
if (!match && (params = matcher(location.path(), path))) {
match = inherit(route, {
params: extend({}, location.search(), params),
pathParams: params});
match.$route = route;
}
});
// No route matched; fallback to "otherwise" route
return match || this.routes[null] && inherit(this.routes[null], {params: {}, pathParams:{}});
}
};

Expand Down Expand Up @@ -339,7 +365,7 @@ function $RouteProvider(){
}

function updateRoute() {
var next = parseRoute(),
var next = $route.match($location),
last = $route.current;

if (next && last && next.$route === last.$route
Expand Down Expand Up @@ -409,25 +435,6 @@ function $RouteProvider(){
}
}


/**
* @returns the current active route, by matching it against the URL
*/
function parseRoute() {
// Match a route
var params, match;
forEach(routes, function(route, path) {
if (!match && (params = matcher($location.path(), path))) {
match = inherit(route, {
params: 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 interpolation of the redirect path with the parametrs
*/
Expand Down