This repository was archived by the owner on Apr 12, 2024. It is now read-only.
File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -212,10 +212,14 @@ function $RouteProvider(){
212
212
* Sets route definition that will be used on route change when no other route definition
213
213
* is matched.
214
214
*
215
- * @param {Object } params Mapping information to be assigned to `$route.current`.
215
+ * @param {Object|string } params Mapping information to be assigned to `$route.current`.
216
+ * If called with a string, the value maps to `redirectTo`.
216
217
* @returns {Object } self
217
218
*/
218
219
this . otherwise = function ( params ) {
220
+ if ( typeof params === 'string' ) {
221
+ params = { redirectTo : params } ;
222
+ }
219
223
this . when ( null , params ) ;
220
224
return this ;
221
225
} ;
Original file line number Diff line number Diff line change @@ -460,6 +460,23 @@ describe('$route', function() {
460
460
expect ( onChangeSpy ) . toHaveBeenCalled ( ) ;
461
461
} ) ;
462
462
} ) ;
463
+
464
+
465
+ it ( 'should interpret a string as a redirect route' , function ( ) {
466
+ module ( function ( $routeProvider ) {
467
+ $routeProvider . when ( '/foo' , { templateUrl : 'foo.html' } ) ;
468
+ $routeProvider . when ( '/baz' , { templateUrl : 'baz.html' } ) ;
469
+ $routeProvider . otherwise ( '/foo' ) ;
470
+ } ) ;
471
+
472
+ inject ( function ( $route , $location , $rootScope ) {
473
+ $location . path ( '/unknownRoute' ) ;
474
+ $rootScope . $digest ( ) ;
475
+
476
+ expect ( $location . path ( ) ) . toBe ( '/foo' ) ;
477
+ expect ( $route . current . templateUrl ) . toBe ( 'foo.html' ) ;
478
+ } ) ;
479
+ } ) ;
463
480
} ) ;
464
481
465
482
You can’t perform that action at this time.
0 commit comments