我的Gruntfile配置有问题,但我不知道如何解决这个问题。当我的路径有单一路由ex:localhost:9000 /承包商重新加载工作正常,但当重新加载localhost:9000 / add / something我得到错误404因为浏览器搜索文件在'添加'目录不在主目录示例中: GET localhost:9000 / add / bower_components / bootstrap / dist / css / bootstrap.css 目录'添加'不存在。我使用的是Angular 1.6.0和angular-route 1.6.0
Gruntfile.js
'use strict';
var modRewrite = require('connect-modrewrite');
var config = {app: 'app'};
var mountFolder;
module.exports = function (grunt)
{
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-connect');
grunt.loadNpmTasks('grunt-contrib-jshint');
require('load-grunt-tasks')(grunt);
mountFolder = function (connect, dir)
{
return connect['static'](require('path').resolve(dir));
};
grunt.initConfig({
config: config,
watch: {
livereload: {
options: {
livereload: '<%= connect.options.livereload %>'
},
files: ['<%= config.app %>/index.html',
'<%= config.app %>/*.js',
'<%= config.app %>/modules/**/*']
}
},
connect: {
options: {
port: 9000,
livereload: 35729,
hostname: 'localhost'
},
livereload: {
options: {
open: true,
middleware: function (connect)
{
return [
// in case of using html5Mode - makes accessible uris without hashbang but containing view's path
modRewrite(['!\\.html|\\.js|\\.svg|\\.css|\\.png|\\.jpg|\\.ttf|\\.woff|(\\api.+)$ /index.html [L]']),
mountFolder(connect, config.app),
connect().use('/bower_components', connect.static('./bower_components')),
require('grunt-connect-proxy/lib/utils').proxyRequest];
}
}
},
proxies: [{
context: '/api',
host: 'localhost',
port: 3000,
changeOrigin: true
}],
jshint: {
default: {
options: {
jshintrc: true
},
files: {
src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']
}
},
verify: {
options: {
jshintrc: true,
reporter: 'checkstyle',
reporterOutput: 'target/jshint.xml'
},
files: {src: ['app/**/*.js', 'test/**/*.js', '!app/bower_components/**/*.js']}
}
}
}
}
);
grunt.registerTask('serve', ['configureProxies', 'connect:livereload', 'watch']);
grunt.registerTask('default', ['serve']);
};
我的家属:
"devDependencies": {
"connect-livereload": "0.5.2",
"connect-modrewrite": "0.9.0",
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-contrib-connect": "0.7.1",
"grunt-contrib-jshint": "0.11.3",
"grunt-contrib-watch": "0.6.1",
"grunt-connect-proxy": "0.2",
"load-grunt-tasks": "3.0.0"
}
答案 0 :(得分:0)
问题出在角度路线1.6.0上。我添加
<base href="/" />
在链接css样式和工作之前到index.html。