2013-08-31 55 views
1

從Yeoman角形腳手架進行基本安裝,並且爲了使用壽命,我無法讓路由器加載基本模板。這裏是我的設置Yeoman/Angular/Coffee.when()路由器不會路由 - 不能GET

// index.html 
<body ng-app="mvmdApp"> 
    <div class="container" ng-view=""></div>// not sure how ng-view plays into this 


// app.coffee 
myAppModule = angular.module("mvmdApp", []) 
    .config(($routeProvider, $locationProvider) -> 
    $locationProvider.html5Mode true 

    $routeProvider 
     .when("/", 
     templateUrl: "views/main.html" 
     controller: "MainCtrl" 
    ) 
     .when("/youtube", 
     templateUrl: "views/youtube.html" 
     controller: "YoutubeCtrl" 
    ) 
) 


// main.js 
angular.module('mvmdApp') 
    .controller 'MainCtrl', ($scope) -> 
    $scope.awesomeThingss = [ 
     'HTML5 Boilerplate' 
     'AngularJS' 
     'Karma' 
    ] 

    $scope.youtube = ($scope) -> 
     alert 'hi' 

    .controller "YoutubeCtrl", ($scope) -> 
    alert 'Work!' 


// views/youtube.html 
<div class="youtube-unit"> 
    <div class="outer-frame"> 
    <div class="inner-frame"> 
     <iframe width="560" height="315" src="//www.youtube.com/embed/2FNEiTjcMM0" frameborder="0" allowfullscreen="allowfullscreen"></iframe> 
    </div> 
    </div> 
</div> 

主控制器加載罰款,我至三儘可能地複製它

去localhost:9000/youtube給我一個Cannot GET /youtube消息。我覺得我已經嘗試了各種組合。

回答

0

Html5模式不僅是關於Javascript,它還需要服務器來支持它。

當您嘗試/ youtube時,它首先會轉到服務器,如果服務器無法管理它,您應該呈現角度應用程序,以便路由器可以捕捉路線並顯示您需要的內容。

我不確定Yeoman是否支持html5模式是誠實的。

你可以試試linemanjs它就像Yeoman一樣,它支持html5模式。

如果你想使用約曼,谷歌對HTML5模式自耕農或使用hashbang :)

2

它不是簡單的,但你可以安裝connect-modrewrite中間件和所有你需要做的就是重寫index.html任何路徑。您還必須編輯GruntFile.js以修復實時重新加載,並在生產服務器上進行重寫。看到這裏有關如何去做這個 - http://ericduran.io/2013/05/31/angular-html5Mode-with-yeoman/

+0

看起來很簡單,謝謝! –