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?
The routes in Angular are case sensitive. In the routeconfig, you have specified the url path as "product".
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.
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.
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
There is an option for case insensitivity:
$routeProvider
.when('/home', {
templateUrl: 'pages/home/home-page.tmpl.html',
controller: 'HomeCtrl',
controllerAs: 'home',
caseInsensitiveMatch: true
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With