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

Commit 6bdef8e

Browse files
committed
bug(ngRoute): allow proto inherited properties in route params object
copy route params with angular.copy before using angular.extend which looks only for enumerable own properties Closes #8181
1 parent 52ceec2 commit 6bdef8e

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/ngRoute/route.js

+8-4
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,14 @@ function $RouteProvider(){
141141
* Adds a new route definition to the `$route` service.
142142
*/
143143
this.when = function(path, route) {
144+
//copy original route object to preserve params inherited from proto chain
145+
var routeCopy = angular.copy(route);
146+
if (angular.isUndefined(routeCopy.reloadOnSearch)) {
147+
routeCopy.reloadOnSearch = true;
148+
}
144149
routes[path] = angular.extend(
145-
{reloadOnSearch: true},
146-
route,
147-
path && pathRegExp(path, route)
150+
routeCopy,
151+
path && pathRegExp(path, routeCopy)
148152
);
149153

150154
// create redirection for trailing slashes
@@ -155,7 +159,7 @@ function $RouteProvider(){
155159

156160
routes[redirectPath] = angular.extend(
157161
{redirectTo: path},
158-
pathRegExp(redirectPath, route)
162+
pathRegExp(redirectPath, routeCopy)
159163
);
160164
}
161165

test/ngRoute/routeSpec.js

+17
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,23 @@ describe('$route', function() {
294294
$rootScope.$digest();
295295
expect($route.current).toBeDefined();
296296
}));
297+
298+
it("should use route params inherited from prototype chain", function() {
299+
var BaseRoute = function BaseRoute() {
300+
BaseRoute.prototype.templateUrl = 'foo.html';
301+
};
302+
var route = new BaseRoute();
303+
304+
module(function($routeProvider) {
305+
$routeProvider.when('/foo', route);
306+
});
307+
308+
inject(function($route, $location, $rootScope) {
309+
$location.path('/foo');
310+
$rootScope.$digest();
311+
expect($route.current.templateUrl).toBe('foo.html');
312+
});
313+
});
297314
});
298315

299316

0 commit comments

Comments
 (0)