当我运行gulp时,服务器启动时显示消息: cannot get /。当我指向localhost:3000/app/index.html时,站点重定向到localhost:3000/home,并且工作正常。但是,当我重新加载页面时,它显示: cannot get /home。
请查看以下配置,查看是否遗漏了任何内容:
访问路径: app/index.html
这是我的gulpfile.js:
var gulp = require('gulp'),
nodemon = require('gulp-nodemon'),
jshint = require('gulp-jshint'),
browserSync = require('browser-sync')
modRewrite = require('connect-modrewrite');
gulp.task('lint', function () {
gulp.src('app/js/*.js').pipe(jshint());
});
gulp.task('serve', function() {
browserSync({
server: {
baseDir: "./",
middleware: [
modRewrite([
'!\\.\\w+$ /index.html [L]'
])
]
}
});
});
gulp.task('default', ['lint', 'serve'], function() {
gulp.watch('app/js/*.js', ['lint', browserSync.reload]);
});角度布线文件:
$urlRouterProvider.otherwise("/home");
$stateProvider
.state('home', {
url: "/home",
templateUrl: "app/partials/home.html",
controller: 'HomeCtrl'
})
...非常感谢!
发布于 2015-03-18 20:11:10
在modRewrite中使用以下代码:
['^(^.+)$ /index.html L']
示例:
gulp.task('serve', function() {
browserSync({
server: {
baseDir: "./",
middleware: [
modRewrite(['^([^.]+)$ /index.html [L]'])
]
}
});
});发布于 2015-08-04 16:11:45
对不起,我不知道gulp,但是我用modRewrite模块修复了Gruntfile.js的中间件部分,如下所示:
var modRewrite = require('connect-modrewrite');
...
grunt.initConfig({
...
browserSync: {
...
options: {
server: {
middleware: [
modRewrite(['!\.html|\.js|\.css|\.png$ /index.html [L]'])
]
}
}
...完美的效果!
https://stackoverflow.com/questions/27517315
复制相似问题