2013-07-24 49 views
25

我一直无法找到一个简单的答案,这导致我相信它真的很简单。无论哪种方式,我走了。AngularJS路由案例敏感性

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

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

我需要什么补充,使“/富”,“/富”,“/富”等,都重定向到相同的路径?

+0

也许这个问题将是有益的? http://stackoverflow.com/questions/14994324/angularjs-base-href-case-sensitive –

+0

这似乎有关,但我不完全明白我需要做什么来做这项工作从我。我的假设是,我需要拉一个特定的脚本,并将其包含在我的项目中,但我不知道还需要添加哪些内容。 – ThisLanham

回答

53

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

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

这适用于版本1.2.2。非常感谢@John,这应该被标记为答案! –

+1

你会认为会有$ routeProvider的配置来做到这一点。我猜不会? – RJB

+2

@RJB有:$ routeProvider.caseInsensitiveMatch = true; – Mathew