【问题标题】:angularjs remove index.htmlangularjs 删除 index.html
【发布时间】:2015-05-18 13:20:29
【问题描述】:

更新

AngularJS 现在可以工作了。切换到 WebStorm IDE,但设置也有问题,这对我有帮助:Bower "Git not in the PATH" error(Bower “Git not in the PATH”错误)。

很快我会再次尝试在 WebStorm 下进行 ngrouting。

如何从我的本地主机 URL 中删除 index.html?有类似的问题,但他们帮不了我。

这是我到目前为止所做的:

index.html:

<head><title>MyApp</title></head>    
<body>
  <div ng-view>
      <a href="#/menu">Menu</a>
      <a href="#/main">Main</a>
  </div>
</body>

app.js:

var app = angular.module('myApp', [
  'ngRoute',
  'ngResource',
  'HTML5ModeURLs'
});

config.js:

app.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
    $route.html5Mode(true);

    $routeProvider.
        when('/menu', {
            templateUrl: 'Modules/Menu/view.html',
            controller: 'Modules/Menu/controller'
        }).
        when('/main', {
            templateUrl: 'Modules/Main/view.html',
            controller: 'Modules/Main/controller'
        }).
        otherwise({
            redirectTo: '/menu'
        });
}
]);

【问题讨论】:

  • 这是只能在服务器端完成的事情,您使用的是哪种服务器? (Apache / node.js...)
  • 我正在使用 IIS Express。

标签: javascript html angularjs iis iis-express


【解决方案1】:

您尝试从您的应用网址中删除 index.html 吗?

app.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$route.html5Mode(true);

$routeProvider.
     when('/', {
        templateUrl: 'index.html',
        controller: 'HomeCtrl'
    }).
    when('/menu', {
        templateUrl: 'Modules/Menu/view.html',
        controller: 'Modules/Menu/controller'
    }).
    when('/main', {
        templateUrl: 'Modules/Main/view.html',
        controller: 'Modules/Main/controller'
    }).
    otherwise({
        redirectTo: '/menu'
    });
  }
]);

设置路线“/”应该可以完成我猜的工作。反正我就是这么干的。

【讨论】:

  • 以防万一:您是否在文档 中设置了 (用于 html5Mode)?
  • 我设置的。似乎 Visual Studio 没有检测到 AngularJS。 (请参阅我更新的问题)。当然,我在 'htm'l 标签中有 ng-app="myApp"。
【解决方案2】:

您正在使用 IIS Express 来托管您的 AngularJS 应用程序文件,所以我认为 topic 正是您要寻找的。 Yagiz Ozturk 解决方案建议您以这种方式配置 IIS 服务器来重写 URL,这样您就可以跳过 index.html 部分:

<system.webServer>
<rewrite>
  <rules>
    <rule name="AngularJS" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>

【讨论】:

  • 把它放在我的网络配置中。仍然有localhost:10203/App/index.htmllocalhost:10203/App/index.html#/menulocalhost:10203/App/index.html#/main 作为网址。我还在服务器上安装了 iis 的 url 重写器,并在 index.html 中添加了一个基本的 href。当我从 href 中删除 # 时出现“Owin”错误,但安装了 Microsoft.Web.Infrastructure 并进行了引用。
  • 应用程序服务器错误,“Owin,版本=1.0.0.0,文化=中性,PublicKeyToken=f0​​ebd12fd5e55cc5”找不到。系统找不到文件错误。
猜你喜欢
  • 2012-04-04
  • 2014-04-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-01-04
  • 2014-02-26
相关资源
最近更新 更多