Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4bdf4db

Browse files
committedNov 1, 2014
feat($routeProvider): allow setting caseInsensitiveMatch on the provider
Fixes angular#6477
1 parent 2a2fd14 commit 4bdf4db

File tree

2 files changed

+40
-3
lines changed

2 files changed

+40
-3
lines changed
 

‎src/ngRoute/route.js

+15-3
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,13 @@ function $RouteProvider() {
141141
* Adds a new route definition to the `$route` service.
142142
*/
143143
this.when = function(path, route) {
144+
var routeWithDefaults = angular.extend({
145+
reloadOnSearch: true,
146+
caseInsensitiveMatch: this.caseInsensitiveMatch
147+
}, route);
144148
routes[path] = angular.extend(
145-
{reloadOnSearch: true},
146-
route,
147-
path && pathRegExp(path, route)
149+
routeWithDefaults,
150+
path && pathRegExp(path, routeWithDefaults)
148151
);
149152

150153
// create redirection for trailing slashes
@@ -162,6 +165,15 @@ function $RouteProvider() {
162165
return this;
163166
};
164167

168+
/**
169+
* @ngdoc property
170+
* @name $routeProvider#caseInsensitiveMatch
171+
*
172+
* @property {boolean} caseInsensitiveMatch Value of the `caseInsensitiveMatch` property
173+
* for newly defined routes. Defaults to `false`.
174+
*/
175+
this.caseInsensitiveMatch = false;
176+
165177
/**
166178
* @param path {string} path
167179
* @param opts {Object} options

‎test/ngRoute/routeSpec.js

+25
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,31 @@ describe('$route', function() {
237237
});
238238
});
239239

240+
it('should allow configuring caseInsensitiveMatch on the route provider level', function() {
241+
module(function($routeProvider) {
242+
$routeProvider.caseInsensitiveMatch = true;
243+
$routeProvider.when('/Blank', {template: 'blank'});
244+
$routeProvider.otherwise({template: 'other'});
245+
});
246+
inject(function($route, $location, $rootScope) {
247+
$location.path('/bLaNk');
248+
$rootScope.$digest();
249+
expect($route.current.template).toBe('blank');
250+
});
251+
});
252+
253+
it('should allow overriding provider\'s caseInsensitiveMatch setting on the route level', function() {
254+
module(function($routeProvider) {
255+
$routeProvider.caseInsensitiveMatch = true;
256+
$routeProvider.when('/Blank', {template: 'blank', caseInsensitiveMatch: false});
257+
$routeProvider.otherwise({template: 'other'});
258+
});
259+
inject(function($route, $location, $rootScope) {
260+
$location.path('/bLaNk');
261+
$rootScope.$digest();
262+
expect($route.current.template).toBe('other');
263+
});
264+
});
240265

241266
it('should not change route when location is canceled', function() {
242267
module(function($routeProvider) {

0 commit comments

Comments
 (0)
Please sign in to comment.