angularjs remove index.html

angularjs remove index.html

本文关键字:html index remove angularjs      更新时间:2023-09-26

更新

AngularJS现在工作。切换到WebStorm IDE,但在设置它时也遇到了问题,这对我很有帮助:Bower"Git不在PATH中";error(Bower"Git不在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'
        });
}
]);

您试图从应用程序url中删除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'
    });
  }
]);

我想设置路线"/"就可以了。我就是这么做的。

您正在使用IIS Express来托管AngularJS应用程序文件,所以我认为这个主题正是您想要的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>