6

gulp を実行すると、サーバーが次のメッセージで起動しました: cannot get /. 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]);
});

角度ルート ファイル:

  $urlRouterProvider.otherwise("/home");

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

どうもありがとう!

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

4

2 に答える 2

0

申し訳ありませんが、gulp についてはわかりませんが、Gruntfile.js を使用して、次のように modRewrite モジュールでミドルウェア部分を修正しました。

var modRewrite = require('connect-modrewrite');

...

grunt.initConfig({
    ...
    browserSync: {
        ...
        options: {
            server: {
                middleware: [
                    modRewrite(['!\.html|\.js|\.css|\.png$ /index.html [L]'])
                ]
            }
        }
...

完璧に動作します!

于 2015-08-04T08:11:45.373 に答える