Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'otherwise' wrapper method to route-segment #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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