From 8724e97b7e6638797d3607a45682ef0b76311aae Mon Sep 17 00:00:00 2001 From: Igor Minar Date: Tue, 1 Feb 2011 20:16:30 -0800 Subject: $route redirection should interpolate variables --- src/services.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/services.js b/src/services.js index b215dcdf..9dfdd35e 100644 --- a/src/services.js +++ b/src/services.js @@ -801,7 +801,7 @@ angularServiceInject('$route', function(location, $updateView) { } }; function updateRoute(){ - var childScope, routeParams, pathParams; + var childScope, routeParams, pathParams, redirectPath, segmentMatch, key; $route.current = _null; forEach(routes, function(rParams, rPath) { @@ -817,7 +817,18 @@ angularServiceInject('$route', function(location, $updateView) { if(routeParams) { if (routeParams.redirectTo) { - location.updateHash(routeParams.redirectTo); + redirectPath = ''; + forEach(routeParams.redirectTo.split(':'), function(segment, i) { + if (i==0) { + redirectPath += segment; + } else { + segmentMatch = segment.match(/(\w+)(.*)/); + key = segmentMatch[1]; + redirectPath += pathParams[key] || location.hashSearch[key]; + redirectPath += segmentMatch[2] || ''; + } + }); + location.updateHash(redirectPath); $updateView(); //TODO this is to work around the $location<=>$browser issues return; } -- cgit v1.2.3