Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Case insensitivity with angularjs ui-router

Tags:

I'm building a new angularJS app, based from the AngularJS SPA Visual studio template (http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83)

this uses ui-router (https://github.com/angular-ui/ui-router) for its routing.

however, it seems to be case sensitive.

Any idea how I would instruct angular/ui-router to ignore the case of the url parameter?

case sensitivity doesn't matter while in the app, though should a user type a url to enter the application at a specific page, we need to ensure that about is also the same as aBouT

Cheers

like image 339
Darren Wainwright Avatar asked Feb 18 '14 19:02

Darren Wainwright


People also ask

How do I make a route sensitive case in AngularJS?

Nothing is being displayed in the layout View. 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.

What is UI-Router in AngularJS?

Angular-UI-Router is an AngularJS module used to create routes for AngularJS applications. Routes are an important part of Single-Page-Applications (SPAs) as well as regular applications and Angular-UI-Router provides easy creation and usage of routes in AngularJS.

What is the use of $state in AngularJS?

$stateProvider is used to define different states of one route. You can give the state a name, different controller, different view without having to use a direct href to a route. There are different methods that use the concept of $stateprovider in AngularJS.

What is UI sref in AngularJS?

ui-sref stands for UI-Router state reference. It's a way to change states/state params (as defined in using the $stateProvider in a config block using the ui. router module for AngularJS. You can read the ui-sref documentation here.


1 Answers

You can now configure ui-router to be case insensitive directly. Here is how you can use it:

angular.module('main', ['ui.router']);  angular.module('main').config(['$urlMatcherFactoryProvider', '$stateProvider', '$urlRouterProvider',   function($urlMatcherFactory, $stateProvider, $urlRouter) {     $urlMatcherFactory.caseInsensitive(true);     $urlMatcherFactory.strictMode(false);     $stateProvider.state('foo', {       url: '/foo',       template: '<b>The Foo View</b>'     });     $stateProvider.state('bar', {       url: '/bar',       template: '<b>The Bar View</b>'     });     $stateProvider.state('nomatch', {       url: '/nomatch',       template: '<b>No match found View</b>'     });      $urlRouter.otherwise('/nomatch');   } ]); 

In the latest release (0.2.11), this is broken. A fix has been pushed already that can be seen at Github. So, currently, the best solution is to clone ui-router and build the head of master manually. Alternatively, you can just alter the source manually until the next release comes.

UPDATE (11/18/2014):

A release has now been made that incorporates the fix from above so that you no longer have to pull source and build manually. You can view the release on Github or just get the latest build.

like image 70
kmkemp Avatar answered Sep 21 '22 13:09

kmkemp