Case insensitivity with angularjs ui-router
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.
각도/ui-router에게 어떻게 지시해야 이 경우를 무시할 수 있는지 알 수 있습니까?url
매개변수?
사용자가 특정 페이지에 애플리케이션을 입력하기 위해 url을 입력하는 경우, 우리는 앱에 있는 동안 대소문자 민감도는 중요하지 않습니다.about
와 같습니다.aBouT
Cheers
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.
Following the link in the comments to the original question, i was able to get the answer I needed.
내앞에$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
});
본질적으로 그럴 것입니다.toLowerCase()
모두 소문자가 아닌 URL.
Once done, it replaces the url rather than redirects. Then carries on with matching a state.
You shouldn't change how ui-route handles URL matching to accept case insensitive URLs (that will have unexpected problems), but you can attempt to correct URLs for the user automatically when the routes fail.
ui-route가 URL과 경로를 일치시킬 수 없을 때 트리거됩니다.otherWise()
콜백이 콜백을 사용하여 리디렉션해야 한다는 것을 보여드리겠습니다.
The following makes the assumption that all URLs for your app should be in lower case.
var stateHandler = function($urlRouterProvider)
{
$urlRouterProvider.otherwise(function($injector, $location)
{
var url = $location.absUrl();
var redirect = url.toLowerCase();
if(url == redirect)
{
return;
}
$window.location = redirect;
});
};
YourAngularApp.config(['$urlRouterProvider',stateHandler]);
If you need more control, then use a regex to select which URLs need rewriting.
According to official wiki,
https://github.com/angular-ui/ui-router/wiki/URL-Routing
대런의 대답은 옳아 보입니다.
app.config(function ($urlRouterProvider) {
// Here's an example of how you might allow case insensitive urls
$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
});}
언급URL : https://stackoverflow.com/questions/21863670/case-insensitivity-with-angularjs-ui-router
'source' 카테고리의 다른 글
xcode6 베타 6 osx 스위프트 프로젝트에서 개체('po')를 인쇄할 수 없습니다. (자동 가져오기 오류: AST 컨텍스트에서 '_ObjC' 모듈을 가져오지 못했습니다.) (0) | 2023.10.04 |
---|---|
"제어가 비공수 기능의 끝에 도달한다"는 것은 무엇을 의미합니까? (0) | 2023.10.04 |
jQuery에서 특정 ID를 가진 모든 요소를 선택하는 방법? (0) | 2023.10.04 |
"net use * /delete"가 작동하지 않고 PowerShell 스크립트에서 확인을 기다리는 이유는 무엇입니까? (0) | 2023.10.04 |
WPF에서 데이터 그리드를 새로 고치는 방법 (0) | 2023.10.04 |