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

feat(ngRoute): alias string as redirectTo property in .otherwise() #7809

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
7 changes: 5 additions & 2 deletions src/ngRoute/route.js
Original file line number Diff line number Diff line change
@@ -158,7 +158,6 @@ function $RouteProvider(){
pathRegExp(redirectPath, route)
);
}

return this;
};

@@ -211,10 +210,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} params Mapping information to be assigned to `$route.current`. If of type
* string, the value is assumed to map to `redirectTo`.
* @returns {Object} self
*/
this.otherwise = function(params) {
if(typeof params === 'string') {
params = {redirectTo: params};
}
this.when(null, params);
return this;
};
17 changes: 17 additions & 0 deletions test/ngRoute/routeSpec.js
Original file line number Diff line number Diff line change
@@ -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');
});
});
});