diff --git a/src/ngRoute/route.js b/src/ngRoute/route.js index b140ddfb..9ffabc32 100644 --- a/src/ngRoute/route.js +++ b/src/ngRoute/route.js @@ -212,10 +212,14 @@ function $RouteProvider(){ * Sets route definition that will be used on route change when no other route definition * is matched. * - * @param {Object} params Mapping information to be assigned to `$route.current`. + * @param {Object|string} params Mapping information to be assigned to `$route.current`. + * If called with a string, the value maps to `redirectTo`. * @returns {Object} self */ this.otherwise = function(params) { + if (typeof params === 'string') { + params = {redirectTo: params}; + } this.when(null, params); return this; }; diff --git a/test/ngRoute/routeSpec.js b/test/ngRoute/routeSpec.js index 220d4f47..8a0a370f 100644 --- a/test/ngRoute/routeSpec.js +++ b/test/ngRoute/routeSpec.js @@ -460,6 +460,23 @@ describe('$route', function() { expect(onChangeSpy).toHaveBeenCalled(); }); }); + + + it('should interpret a string as a redirect route', function() { + module(function($routeProvider) { + $routeProvider.when('/foo', {templateUrl: 'foo.html'}); + $routeProvider.when('/baz', {templateUrl: 'baz.html'}); + $routeProvider.otherwise('/foo'); + }); + + inject(function($route, $location, $rootScope) { + $location.path('/unknownRoute'); + $rootScope.$digest(); + + expect($location.path()).toBe('/foo'); + expect($route.current.templateUrl).toBe('foo.html'); + }); + }); });