browserSync的modRewrite不适用于angularjs html5mode的path“app / index.html”与吞咽
当我运行gulp时,服务器以消息开始:不能得到/。 当我指向localhost:3000 / app / index.html时,站点redirect到localhost:3000 / home并正常工作。 但是,当我重新加载页面,它给:不能得到/ home。
请检查以下configuration,看看是否有遗漏:
访问path: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]']) ] } }); });
对不起,我不知道有关gulp,但与Gruntfile.js我用modRewrite模块固定中间件部分,如下所示:
var modRewrite = require('connect-modrewrite'); ... grunt.initConfig({ ... browserSync: { ... options: { server: { middleware: [ modRewrite(['!\.html|\.js|\.css|\.png$ /index.html [L]']) ] } } ...
完美的作品!