不区分大小写与angularjs UI路由器 [英] Case insensitivity with angularjs ui-router

查看:367
本文介绍了不区分大小写与angularjs UI路由器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个新的应用程序angularJS从AngularJS SPA Visual Studio的基于模板的(<一个href=\"http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83\">http://visualstudiogallery.msdn.microsoft.com/5af151b2-9ed2-4809-bfe8-27566bfe7d83)

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)

本使用UI的路由器( https://github.com/angular-ui/ui-router )为它的路由。

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

不过,这似乎是区分大小写。

however, it seems to be case sensitive.

任何想法,我怎么会指示角/ UI路由器忽略网​​址的情况下参数?

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

而在应用程序,但应该在用户键入URL在特定页面进入应用大小写没关系,我们需要确保关于是也一样关于

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

干杯

推荐答案

继在评论中原来的问题的联系,我能得到我所需要的答案。

Following the link in the comments to the original question, i was able to get the answer I needed.

我的 $ stateProvider.state(......)路线之前,我现在有了这块code的:

Before my $stateProvider.state(......) routes I now have this piece of code:

$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
    });

从本质上讲它会与toLowerCase()的URL是不是所有的小写了。

Essentially it will toLowerCase() a url that isn't all lowercase already.

一旦完成,它将替换URL,而不是重定向。然后用匹配的状态进行。

Once done, it replaces the url rather than redirects. Then carries on with matching a state.

这篇关于不区分大小写与angularjs UI路由器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆