与angularjs ui-router不区分大小写

Dar*_*ght 25 angularjs angular-ui-router

我正在构建一个新的angularJS应用程序,基于AngularJS SPA Visual studio模板(http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83)

这使用ui-router(https://github.com/angular-ui/ui-router)进行路由.

但是,它似乎区分大小写.

知道如何指示angular/ui-router忽略url参数的情况吗?

在应用程序中区分大小写无关紧要,但是如果用户键入一个URL以在特定页面上输入应用程序,我们需要确保它about也是相同的aBouT

干杯

kmk*_*emp 30

您现在可以将ui-router配置为不区分大小写.以下是如何使用它:

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');
  }
]);
Run Code Online (Sandbox Code Playgroud)

在最新版本(0.2.11)中,这被打破了.已经推出了一个可以在Github上看到的修复程序.因此,目前,最好的解决方案是克隆ui-router并手动构建master的头部.或者,您可以手动更改源,直到下一个版本发布.

更新(2014年11月18日):

现在已经发布了一个版本,其中包含了上面的修复程序,因此您不再需要手动提取源代码并进行构建.您可以在Github上查看该版本或只获取最新版本.


Dar*_*ght 15

根据对原始问题的评论中的链接,我能够得到我需要的答案.

在我的$stateProvider.state(......)路线之前,我 现在有了这段代码:

$urlRouterProvider.rule(function ($injector, $location) {
       //what this function returns will be set as the $location.url
        var path = $location.path(), normalized = path.toLowerCase();
        if (path != normalized) {
            //instead of returning a new url string, I'll just change the $location.path directly so I don't have to worry about constructing a new url string and so a new state change is not triggered
            $location.replace().path(normalized);
        }
        // because we've returned nothing, no state change occurs
    });
Run Code Online (Sandbox Code Playgroud)

基本上它将toLowerCase()是一个并非全部小写的URL.

完成后,它将替换url而不是重定向.然后进行匹配状态.