How to tell gulp-connect to open index.html regardless of the URL?

那年仲夏 提交于 2019-12-03 09:49:23

You can use the middleware option to use the connect-history-api-fallback middleware. Once you've installed and required the fallback, you add it like this:

gulp.task('connect', function() {
  connect.server({
    root: __dirname,
    livereload: true,

    middleware: function(connect, opt) {
      return [ historyApiFallback ];
    }

  });
});

Alternatively you can use gulp-connect own option called fallback for that:

gulp.task('connect', function() {
  connect.server({
    root: 'path/',
    livereload: true,
    fallback: 'path/index.html'
  });
});

No need for another package.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!