2017-03-14 14 views
0

から#を削除するために働いていない私は、角度に新しいです、と私は$locationProvider を使用してURL角度ルートから#を削除しようとしていますが、私のコードは を働いていない私は、この

<html> 
<head> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script> 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular-route.js"></script> 
<base href="/"> 
</head> 
<body ng-app="myApp"> 
<p><a href="/">Main</a></p> 
<a href="/red">Red</a> 
<a href="/green">Green</a> 
<a href="/blue">Blue</a> 
<ng-view></ng-view> 
<script> 
var app = angular.module("myApp", ["ngRoute"]); 
app.config(function($routeProvider, $locationProvider) { 
    $routeProvider 
    .when("/", { 
     templateUrl : "main.html" 
    }) 
    .when("/red", { 
     templateUrl : "red.html" 
    }) 
    .when("/green", { 
     templateUrl : "green.html" 
    }) 
    .when("/blue", { 
     templateUrl : "blue.html" 
    }); 
    $locationProvider.html5Mode(true); 
}); 
</script> 
<p>Click on the links.</p> 
<p>This example uses the ng-view directive as an element.</p> 
</body> 
</html> 

を試してみてください私はまた、URL書き換えを試してみませんか?

<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> 
    </system.webServer> 

誰でも私にこれを手伝ってもらえますか?

答えて

0

あなたのコードは正常に動作しているようです。必要な#すべてを非表示にするには、次のコードを追加するだけです:

$locationProvider.html5Mode(true); 

ブラウザのキャッシュをきれいにしてください。

コンソールに何かエラーがありますか?

+0

すでに$ locationProvider.html5Mode(true)が追加されています。今はきれいなブラウザキャッシュで試してみてください。まだ動作していません – Dinesh