Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make routes case insensitive with Angular

Tags:

angularjs

How can I make routing in angular case insensitive? For example if I have a route for www.example.com/home which looks like this:

$routeProvider
  .when('/home', {
    templateUrl: 'pages/home/home-page.tmpl.html',
    controller: 'HomeCtrl',
    controllerAs: 'home'
  });

How can I also set it up so that it would work with.

www.example.com/Home | www.example.com/HOME | www.example.com/HoMe etc?

like image 313
Jared Whipple Avatar asked Mar 23 '16 05:03

Jared Whipple


People also ask

Is Angular routing case sensitive?

The routes in Angular are case sensitive. In the routeconfig, you have specified the url path as "product".

Which makes routes Path case sensitive in Angular JS routes?

That's because the routes that are configured using UI-Router are case sensitive. To make route insensitive, all you have to do is to inject $urlMatcherFactoryProvider service into the config() function and call caseInsensitive(true) function. Let's go back to our Controller.

Are http routes case sensitive?

It may surprise you but, yes, URLs are case sensitive. And, if you have both upper- and lowercase versions of your site's domain, you may be unintentionally making Google's job harder — and hurting your site's own performance.


2 Answers

Seems you can simply set this property to make all route matching case insensitive

$routeProvider.caseInsensitiveMatch = true;

See https://docs.angularjs.org/api/ngRoute/provider/$routeProvider#caseInsensitiveMatch

like image 75
Phil Avatar answered Oct 31 '22 19:10

Phil


There is an option for case insensitivity:

$routeProvider
  .when('/home', {
       templateUrl: 'pages/home/home-page.tmpl.html',
       controller: 'HomeCtrl',
       controllerAs: 'home',
       caseInsensitiveMatch: true
});
like image 31
Tarun Dugar Avatar answered Oct 31 '22 19:10

Tarun Dugar