2014-09-25 28 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