javascript AngularJS 路由区分大小写

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17824687/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 09:45:46  来源:igfitidea点击:

AngularJS Routing Case Sensitivity

javascriptangularjsurl-routingcase-sensitive

提问by ThisLanham

I haven't been able to find a straightforward answer to this, which leads me to believe that it's something really really simple. Either way, here I go.

我一直无法找到一个直截了当的答案,这让我相信这真的很简单。不管怎样,我来了。

All of the calls in my $routeProvider work great, but are case sensitive. Here's a code sample:

我的 $routeProvider 中的所有调用都很好用,但区分大小写。这是一个代码示例:

config(function ($routeProvider) {
    $routeProvider.
        when('/', { controller: 'TmpCtrl', templateUrl: '/app/home.html' }).
        when('/foo', { controller: 'TmpCtrl', templateUrl: '/app/foo.html' }).  
        otherwise({ redirectTo: '/' });
});

What do I need to add so that '/Foo', '/fOO', '/FoO', etc, all redirect to the same path?

我需要添加什么,以便“/Foo”、“/fOO”、“/FoO”等都重定向到同一路径?

回答by John Sparwasser

There is an option you can pass to $routeProvider to toggle case sensitivity:

有一个选项可以传递给 $routeProvider 来切换区分大小写:

config(function ($routeProvider) {
    $routeProvider.
        when('/', { controller: 'TmpCtrl', templateUrl: '/app/home.html' }).
        when('/foo', { controller: 'TmpCtrl', templateUrl: '/app/foo.html', caseInsensitiveMatch: true }).  
        otherwise({ redirectTo: '/' });
});