diff --git a/lib/commands/serve.js b/lib/commands/serve.js index 9b89633..2e5155d 100644 --- a/lib/commands/serve.js +++ b/lib/commands/serve.js @@ -3,6 +3,7 @@ const serveStatic = require('serve-static') const connect = require('connect') const livereload = require('connect-livereload') +const history = require('connect-history-api-fallback') const lrserver = require('livereload') const open = require('open') const chalk = require('chalk') @@ -27,7 +28,8 @@ module.exports = function ( }) .then(_ => { path = resolve(path || '.') - const indexFile = resolve(path, indexName || 'index.html') + const indexFileName = indexName || 'index.html' + const indexFile = resolve(path, indexFileName) if (!exists(indexFile)) { const msg = @@ -46,6 +48,7 @@ module.exports = function ( port: livereloadPort }) ) + server.use(history({index: '/' + indexFileName})) server.use(serveStatic(path, {index: indexName})) server.listen(port) lrserver diff --git a/package.json b/package.json index 25c7a49..fb9aed3 100644 --- a/package.json +++ b/package.json @@ -55,6 +55,7 @@ "dependencies": { "chalk": "^2.4.2", "connect": "^3.6.0", + "connect-history-api-fallback": "^1.6.0", "connect-livereload": "^0.6.0", "cp-file": "^7.0.0", "docsify": "^4.12.2",