2016-03-18 15 views
0

私は自分のURLから#を削除したいので、私は以下のコードがあります。

angular.module('building') 
    .config(['$stateProvider', '$locationProvider', 
     function ($stateProvider, $locationProvider) { 

      // Turn on #-less links. 
      $locationProvider.html5Mode(true); 

      $stateProvider 
       .state('building', { 
        url:'/building', 
        templateUrl: 'app/modules/building/building.html', 
        controller: 'BuildingQuery', 
        controllerAs: 'vm' 
      }) 

    }]); 

をそして、私は私のindex.htmlファイルに<base href="/">を持っています。

そしてコードは動作します。

私はこのようなリンクを入力した場合...

http://127.0.0.1:4000/#/building 

その後、ブラウザはそのURLが...

http://127.0.0.1:4000/building 

とページをロードにリダイレクトします。その後、

しかし、私はこのURLを入力すると...

http://127.0.0.1:4000/building 

...

Cannot GET /building 

# URLが適切にリダイレクトするので、私は$locationProvider.html5Mode(true);何かをやっている知っています。

アイデア?モジュールを生成するのに私がangmを使用していることを知っておくと役に立ちます。角度docsから

答えて

0

[html5mode]使い方は基本的に、あなたのアプリケーション のエントリポイント(例えばindex.htmlを)へのすべてのリンクを書き換える必要があり 、サーバ側でURL書き換えを要求します。 ベースの>タグを必要とすることは、アプリケーションベースである URLの部分と処理されるべきパスとを区別するために、この の場合にも重要です。

e.e.e.あなたのサーバーに、/ building//へのリクエストを/index.htmlに書き直すように伝える必要があります。

+0

のためでした。明らかです。ありがとう! – crowhill

0

evsheinoが正しい方向に私を指摘しました。私のコードには何も問題はありません。問題を引き起こしたサーバー構成でした。 http://jjt.io/2013/11/16/angular-html5mode-using-yeoman-generator-angular/

EDITを::私がしなければならなかったすべては

middleware: function (connect, options) { 
    var optBase = (typeof options.base === 'string') ? [options.base] : options.base; 
        return [require('connect-modrewrite')(['!(\\..+)$/[L]'])].concat(
         optBase.map(function(path){ return connect.static(path); })); 
       }, 
       keepalive: true, 
       port: 4000, 
       base: '.', 
       hostname: 'localhost', 
       debug: true, 
       livereload: true, 
       open: true 
      } 
     } 
    }, 

詳しい説明はここで見つけることができます私のgruntfile.jsに以下を追加しましたこれはconnectもちろん