我在让具有 grunt-serve 任务的本地服务器表现得像普通服务器一样时遇到问题。我的 grunt.initConfig 对象如下所示:
grunt.initConfig({
'serve': {
'path': '/Users/honkdonky/Desktop/testspace/angular',
},
'options': {
'port': '9999'
}
}
});
但是当我请求此链接时:
index.html 没有呈现。相反,我看到的是可用文件的列表。该项目应通过渲染 index.html 并将请求路由到“/”,并按照 angularjs 模块中配置的方式进行路由。配置如下:
phoneApp.config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/phones', {
templateUrl: 'phone-list.html',
controller: 'PhoneListCtrl'
}).
when('/phones/:phoneId', {
templateUrl: 'phone-detail.html',
controller: 'PhoneDetailCtrl'
}).
otherwise({
redirectTo: '/phones'
});
}
]);
最佳答案
grunt-serve包用于运行任务和提供文件,它不能渲染/到index.html,如果您需要Web服务器,可以使用grunt-contrib-connect .
关于javascript - grunt-serve 不提供带有 '/' 请求的 index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36908837/