【问题标题】:Gulp Serve: render index.html for all pathsGulp Serve:为所有路径渲染 index.html
【发布时间】:2016-02-23 03:32:22
【问题描述】:

我正在运行一个简单的 AngularJS 应用程序,并使用 Gulp / Gulp Serve 和 Browsersync 为它提供服务。

为了使我的 Angular 路由正常工作,我需要为端口上的所有路径渲染 /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);
});

【问题讨论】:

    标签: javascript node.js gulp browser-sync


    【解决方案1】:

    解决方案是使用这个中间件,connect-history-api-fallback,如下所示:

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

    现在完美运行!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-01
      • 2019-10-29
      • 2022-01-21
      • 1970-01-01
      • 2023-03-06
      相关资源
      最近更新 更多