Skip to content
Open
Show file tree
Hide file tree
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
13 changes: 11 additions & 2 deletions src/route-segment.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,16 @@ mod.provider( '$routeSegment',
segmentRoutes[name] = route;
return this;
};


/**
* The shorthand for $routeProvider.otherwise() method with specified route.
* @param {string|function} route Route URL, e.g. '/'; or function that return a URL
*/
$routeSegmentProvider.otherwise = function(route) {
$routeProvider.otherwise({redirectTo: route});
return this;
};

// Extending the provider with the methods of rootPointer
// to start configuration.
angular.extend($routeSegmentProvider, rootPointer);
Expand Down Expand Up @@ -409,7 +418,7 @@ mod.provider( '$routeSegment',
params.watcher,
{},
{segment: $routeSegment.chain[index]});
}
};

var lastWatcherValue = getWatcherValue();

Expand Down
9 changes: 9 additions & 0 deletions test/unit/route-segment.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,15 @@ describe('route segment', function() {

});

it('should redirect to / when invalid section', function () {
$routeSegmentProvider.otherwise('/1');

$location.path('/invalid');
$rootScope.$broadcast('$locationChangeSuccess', $location.absUrl(), null);
$rootScope.$on('$locationChangeSuccess', function() {
expect($location.url()).toBe('/1');
});
});

it('should auto-fetch templateUrl by $http', function () {

Expand Down