Gulp Serve:为所有path渲染index.html

我正在运行一个简单的AngularJS应用程序,并使用浏览器同步使用Gulp / Gulp服务。

为了使我的Angular路线工作,我需要为端口上的所有path渲染/index.html

我该怎么做呢? 我目前的代码是:

 gulp.task('serve', ['less'], function() { browserSync.init({ server: "./app" }); gulp.watch("app/css/*.less", ['less']); gulp.watch("app/*.html").on('change', browserSync.reload); gulp.watch("app/js/**/*.js").on('change', browserSync.reload); }); 

解决的办法是使用这个中间件, connect-history-api-fallback ,就像这样:

 gulp.task('serve', ['less'], function() { browserSync.init({ server: { baseDir: "./app", middleware: [ history() ] } }); }); 

现在完美的工作!