angularjs ui-router 不区分大小写 [英] Case insensitivity with angularjs ui-router
问题描述
我正在构建一个基于 AngularJS SPA Visual Studio 模板的新 angularJS 应用程序 (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-router (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.
知道如何指示 angular/ui-router 忽略 url
参数的大小写吗?
Any idea how I would instruct angular/ui-router to ignore the case of the url
parameter?
在应用程序中区分大小写无关紧要,但如果用户在特定页面输入网址进入应用程序,我们需要确保 about
也与 关于
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(......)
路由之前,我现在有这段代码:
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-router 不区分大小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!