diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index a9f88ceeb605..7a51a78cf689 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -141,10 +141,14 @@ function $RouteProvider(){ * Adds a new route definition to the `$route` service. */ this.when = function(path, route) { + //copy original route object to preserve params inherited from proto chain + var routeCopy = angular.copy(route); + if (angular.isUndefined(routeCopy.reloadOnSearch)) { + routeCopy.reloadOnSearch = true; + } routes[path] = angular.extend( - {reloadOnSearch: true}, - route, - path && pathRegExp(path, route) + routeCopy, + path && pathRegExp(path, routeCopy) ); // create redirection for trailing slashes @@ -155,7 +159,7 @@ function $RouteProvider(){ routes[redirectPath] = angular.extend( {redirectTo: path}, - pathRegExp(redirectPath, route) + pathRegExp(redirectPath, routeCopy) ); } diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 45668c3c2209..0e90d6ae9508 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -294,6 +294,23 @@ describe('$route', function() { $rootScope.$digest(); expect($route.current).toBeDefined(); })); + + it("should use route params inherited from prototype chain", function() { + var BaseRoute = function BaseRoute() { + BaseRoute.prototype.templateUrl = 'foo.html'; + }; + var route = new BaseRoute(); + + module(function($routeProvider) { + $routeProvider.when('/foo', route); + }); + + inject(function($route, $location, $rootScope) { + $location.path('/foo'); + $rootScope.$digest(); + expect($route.current.templateUrl).toBe('foo.html'); + }); + }); });