2015-05-18 23 views
2

UPDATEangularjs的index.html刪除

AngularJS現在的作品。切換到WebStorm IDE,但也有問題設置它,幫助我:Bower "Git not in the PATH" error(鮑爾「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' 
     }); 
} 
]); 
+0

這一點是可以做到的僅服務器端,您使用的是哪種服務器? (Apache/node.js ...) – bviale

+0

我正在使用IIS Express。 –

回答

2

您嘗試從您的應用程序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' 
    }); 
    } 
]); 

設定路線 '/' 應該做我猜工作。無論如何,我就是這麼做的。

+0

嘗試了它,但仍然得到http:// localhost:10203/App/index.html作爲url –

+0

只是在以下情況下:是否在文檔(對於html5Mode)中設置了? – enguerranws

+0

我設定了。看起來像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> 

+0

把它放在我的網頁配置中。仍然有http:// localhost:10203/App/index.html,http:// localhost:10203/App/index.html#/ menu,http:// localhost:10203/App/index.html#/ main網址。我還在服務器上安裝了iis的url重寫器,並在index.html中添加了基礎href。當我從href中刪除#時,出現'Owin'錯誤,但是Microsoft.Web.Infrastructure被安裝並且引用了。 –

+0

如果您轉到http:// localhost:10203 /?會發生什麼情況? – bviale

+0

application servererror,「Owin,Version = 1.0.0.0,Culture = neutral,PublicKeyToken = f0ebd12fd5e55cc5」找不到。系統找不到文件錯誤。 –