1) npm install --save-dev connect-modrewrite
2) configure Gruntfile.js according to the "MODIFIED" sections below
Last active
February 11, 2020 09:39
-
-
Save nnarhinen/7719157 to your computer and use it in GitHub Desktop.
Support html5 pushState (or angular.js html5mode) in a yeoman (grunt-contrib-connect) application.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module.exports = function (grunt) { | |
// show elapsed time at the end | |
require('time-grunt')(grunt); | |
// load all grunt tasks | |
require('load-grunt-tasks')(grunt); | |
//MODIFIED: add require for connect-modewrite | |
var modRewrite = require('connect-modrewrite'); | |
grunt.initConfig({ | |
//omitted, normal configuration, depends on your template | |
connect: { | |
options: { | |
port: 9000, | |
livereload: 35729, | |
// change this to '0.0.0.0' to access the server from outside | |
hostname: 'localhost' | |
}, | |
livereload: { | |
options: { | |
open: true, | |
base: [ | |
'.tmp', | |
'<%= yeoman.app %>' | |
], | |
// MODIFIED: Add this middleware configuration | |
middleware: function(connect, options) { | |
var middlewares = []; | |
middlewares.push(modRewrite(['^[^\\.]*$ /index.html [L]'])); //Matches everything that does not contain a '.' (period) | |
options.base.forEach(function(base) { | |
middlewares.push(connect.static(base)); | |
}); | |
return middlewares; | |
} | |
} | |
} | |
} | |
//Omitted, normal configuration | |
}); |
Worked for me! Thanks
I used html5 history for router. While refresh the page i am getting 404 error. how to resolve this?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I used this solution, and everything seems allrigth but... only when a run grunt serve, when i want to make a dist all the files included css and js... shows a undefined in the attachment, the path and files are fine, in the stablished path with the code neccesary
undefined I am using Yeoman why happen this?, when a disable the solution the dist is okexample: