2014-03-24 217 views
1

我試着開始與yeoman開發角度的應用。這聽起來可能很愚蠢,但我在使用yo:angular route創建路線時遇到了問題。Yeoman和角度 - 路由不起作用

當我創建一個使用新的路徑:

yo:angular route foo 

自耕農創建:

app/scripts/controllers/foo.js    (controller) 
app/views/foo.html       (view) 
app/test/spec/controllers/foo.js   (testing the controller) 

在app.js它創建:

.config(function ($routeProvider) { 
    $routeProvider 
    .when('/', { 
    templateUrl: 'views/main.html', 
    controller: 'MainCtrl' 
    }) 
    .when('/foo', { 
    templateUrl: 'views/foo.html', 
    controller: 'FooCtrl' 
    }) 
    .otherwise({ 
    redirectTo: '/' 
    }); 
}); 

所以一切都應該很好地工作。不幸的是,路線不工作 - 當我嘗試打開

http://localhost:9000/foo 

我獲得以下錯誤:

Cannot GET /foo 

在自耕農路線的想法看起來很簡單,我不知道問題出在哪裏。

+0

你如何爲你的應用程序提供服務?節點/阿帕奇/ nginx的/ ..?嘗試在主頁上建立到'/ foo'的鏈接並從主頁訪問它 – doodeec

回答

1

您是否在Angular應用程序中啓用了HTML5模式?如果不是,網址是:

http://localhost:9000/#/foo 

如果你已經在你的應用程序角啓用HTML5模式,你必須確保任何服務器,你正在使用已配置來處理所有的路線,因爲他們是根的應用程序。