AngularJS + Base Href是否区分大小写? [英] AngularJS + Base Href Case Sensitive?

查看:66
本文介绍了AngularJS + Base Href是否区分大小写?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在努力理解为什么我的基本href似乎区分大小写。我有一个带有基本href的页面,并使用了angularjs路由。

I'm struggling to understand why my base href seems to be case sensitive. I have a page with a base href and utilizes angularjs routing.

html:

<html ng-app="app">
    <head>
        <base href="/Foo/"/>
    </head>
    <body>
        <div>Foo</div>
        <div ng-view></div>  
    </body>
</html>

js:

var module = angular.module('app', []);

module.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when('/Home/Page1', { templateUrl = 'partials/page1' })
        .otherwise({ redirectTo: '' });

     $locationProvider.html5Mode(true);
     $locationProvider.hashPrefix('!');
});

如果我导航到 http://www.example.com/Foo/ ,就可以了。但是当我导航到 http://www.example.com/foo/ 时,错误:

If I navigate to http://www.example.com/Foo/, it's fine. But when I navigate to http://www.example.com/foo/ I get an angular error:

Error: Invalid url "http://www.example.com/foo/", missing path prefix "/Foo" !
at Error (<anonymous>)
at Object.LocationUrl.$$parse (http://www.example.com/foo/Scripts/angular.js:4983:13)
at Object.LocationUrl (http://www.example.com/foo/Scripts/angular.js:5014:8)
at $LocationProvider.$get (http://www.example.com/foo/Scripts/angular.js:5387:21)
at Object.invoke (http://www.example.com/foo/Scripts/angular.js:2809:28)
at http://www.example.com/foo/Scripts/angular.js:2647:37
at getService (http://www.example.com/foo/Scripts/angular.js:2769:39)
at Object.invoke (http://www.example.com/foo/Scripts/angular.js:2787:13)
at $CompileProvider.directive (http://www.example.com/foo/Scripts/angular.js:3613:43)
at Array.forEach (native) angular.js:5582

如果有帮助/有所作为,则将站点托管在IIS上并使用MVC 4。

If it helps/makes a difference, site is hosted on IIS and using MVC 4.

推荐答案

您需要可以关闭angularjs路由提供程序的区分大小写。

You need to turn off case sensitivity of angularjs route provider.

请查看此功能的详细信息:
添加 caseInsensitiveMatch 选项以进行网址匹配

Please review the detail of this feature: add caseInsensitiveMatch option for url matching

这篇关于AngularJS + Base Href是否区分大小写?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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