2014-09-25 54 views
0

在ngRoute中使用參數並直接訪問URL(不通過站點內部的鏈接)時,不會加載CSS。除/chef/:id之外,我的所有路線都可以正常工作。我用yeoman的angular generator,我用grunt serve運行的東西。

這裏是我的路線代碼:

angular 
    .module('agFrontApp', [ 
     'configuration', 
     'LocalStorageModule', 
     'ngCookies', 
     'ngRoute', 
     'ngSanitize', 
     'ngTouch' 
    ]) 
    .config(function ($routeProvider, $locationProvider) { 
     $routeProvider 
      .when('/', { 
       templateUrl: '../views/main_view.html', 
       controller: 'MainCtrl', 
       controllerAs: 'MainCtrl', 
      }) 
      .when('/login', { 
       templateUrl: '../views/login_view.html', 
       controller: 'LoginCtrl', 
       controllerAs: 'login', 
      }) 
      .when('/chefs', { 
       templateUrl: '../views/chef_list_view.html', 
       controller: 'ChefListController', 
       controllerAs: 'chefs', 
      }) 
      .when('/chef/:id', { 
       templateUrl: '../views/chef_detail_view.html', 
       controller: 'ChefDetailController', 
       controllerAs: 'chef' 
      }) 
      .when('/receitas', { 
       templateUrl: '../views/recipe_list_view.html', 
       controller: 'RecipeListController', 
       controllerAs: 'recipe' 
      }) 
      .when('/perfil', { 
       templateUrl: '../views/perfil_view.html', 
      }) 
      .otherwise({ 
       redirectTo: '/' 
      }); 
     $locationProvider.html5Mode(true); 

    }); 

這裏是爲/chef/:id控制器:

'use strict'; 

(function() { 

function ChefDetailController($routeParams, $scope, $log, Chefs) { 
    var vm = this; 

    Chefs.getChef($routeParams.id) 
     .then(function(data) { 
      $log.log('success'); 
     }) 
     .fail(function(data) { 
      $log.log('something went wrong'); 
     }); 
} 

angular.module('agFrontApp') 
    .controller('ChefDetailController', 
     [ '$routeParams', '$scope', '$log', 'Chefs', ChefDetailController]); 

})(); 

我在做什麼錯?

編輯:

這裏的chef_detail_view.html:http://pastebin.com/bL5ST01N

+0

我們可以看到,其用於該路由模板代碼 – V31 2014-09-25 14:34:25

+0

好的,這是chef_detail_view.html:http://pastebin.com/bL5ST01N – 2014-09-25 14:53:13

+0

而這裏的index.html的,這裏的模板被加載到:HTTP: //pastebin.com/kzVZX8eE – 2014-09-25 14:54:17

回答

2

你很有可能加載使用相對URL你的CSS像這樣

<link rel="stylesheet" href="styles/style.css" /> 

的問題是在html5mode你的廚師url是/chef/123所以瀏覽器試圖從 /chef/styles/style.css加載你的CSS你想要關閉html5mode或改變你的風格表href是根相對的(例如, /styles/style.css

+0

謝謝你,修好了。 – 2014-09-25 16:19:06