Skip to content

Route provider case sensitivity

Jens Melgaard edited this page Jul 29, 2013 · 6 revisions

Some web servers will ignore caseing, so that http://dotjem.github.com/angular-routing/samples and http://dotjem.github.com/Angular-Routing/Samples would refer to the same thing. (e.g. IIS is known to do this by default)

Just to mirror that, the $routeProvider can turn on a case insensitive mode using the ignoreCase function.

angular.module('phonecat', ['dotjem.routing']).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider
      .ignoreCase()
      .when('/phones', { 
          templateUrl: 'partials/phone-list.html',
          controller: PhoneListCtrl})
      .when('/phones/:phoneId', {
          templateUrl: 'partials/phone-detail.html', 
          controller: PhoneDetailCtrl})
      .otherwise({redirectTo: '/phones'});
}]);

A matchCase method also exist, this is the default state for the $routeProvider and should not be needed, but if you wish to state explicitly that you want the routes to be case-sensitive it can be used to indicate that.

ignoreCase and matchCase are global and can't be turned on for some routes and not others.

It's unnecessary to turn on even for web-servers that ignore case, but if your really use to them you might write links around your application with random casing like: /Articles vs. /articles... and this idiot profs that somewhat.

Clone this wiki locally