当我运行gulp时,服务器启动时显示消息:无法获取/。
当我指向localhost:3000/app/index.html时,站点重定向到localhost:3000/home并正常工作。
但是,当我重新加载页面时,它给出:无法获取/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]);
});

Angular 路线文件:
  $urlRouterProvider.otherwise("/home");

  $stateProvider
    .state('home', {
      url: "/home",
      templateUrl: "app/partials/home.html",
      controller: 'HomeCtrl'
    })
...

非常感谢!

GitHub:https://github.com/yhjor1212/angular-fire-powder

最佳答案

在modRewrite中使用以下代码:

['^([^。] +)$/index.html [L]']

例子:

gulp.task('serve', function() {
  browserSync({
      server: {
          baseDir: "./",
          middleware: [
              modRewrite(['^([^.]+)$ /index.html [L]'])
          ]
      }
  });
});

10-08 13:33
查看更多