AngularJS Routing Case Sensitivity

ThisLanham picture ThisLanham · Jul 24, 2013 · Viewed 11.4k times · Source

I haven't been able to find a straightforward answer to this, which leads me to believe that it's something really really simple. Either way, here I go.

All of the calls in my $routeProvider work great, but are case sensitive. Here's a code sample:

config(function ($routeProvider) {
    $routeProvider.
        when('/', { controller: 'TmpCtrl', templateUrl: '/app/home.html' }).
        when('/foo', { controller: 'TmpCtrl', templateUrl: '/app/foo.html' }).  
        otherwise({ redirectTo: '/' });
});

What do I need to add so that '/Foo', '/fOO', '/FoO', etc, all redirect to the same path?

Answer

John Sparwasser picture John Sparwasser · Jul 26, 2013

There is an option you can pass to $routeProvider to toggle case sensitivity:

config(function ($routeProvider) {
    $routeProvider.
        when('/', { controller: 'TmpCtrl', templateUrl: '/app/home.html' }).
        when('/foo', { controller: 'TmpCtrl', templateUrl: '/app/foo.html', caseInsensitiveMatch: true }).  
        otherwise({ redirectTo: '/' });
});