Skip to content

Commit 5454e70

Browse files
committed
feat(cli-service): add history api fallback for multi-page mode
1 parent be56537 commit 5454e70

File tree

1 file changed

+15
-4
lines changed
  • packages/@vue/cli-service/lib/commands

1 file changed

+15
-4
lines changed

packages/@vue/cli-service/lib/commands/serve.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ module.exports = (api, options) => {
3333
const isProduction = process.env.NODE_ENV === 'production'
3434

3535
const url = require('url')
36-
const path = require('path')
3736
const chalk = require('chalk')
3837
const webpack = require('webpack')
3938
const WebpackDevServer = require('webpack-dev-server')
@@ -139,9 +138,7 @@ module.exports = (api, options) => {
139138
clientLogLevel: 'none',
140139
historyApiFallback: {
141140
disableDotRule: true,
142-
rewrites: [
143-
{ from: /./, to: path.posix.join(options.baseUrl, 'index.html') }
144-
]
141+
rewrites: genHistoryApiFallbackRewrites(options.baseUrl, options.pages)
145142
},
146143
contentBase: api.resolve('public'),
147144
watchContentBase: !isProduction,
@@ -302,6 +299,20 @@ function checkInContainer () {
302299
}
303300
}
304301

302+
function genHistoryApiFallbackRewrites (baseUrl, pages = {}) {
303+
const path = require('path')
304+
const multiPageRewrites = Object
305+
.keys(pages)
306+
.map(name => ({
307+
from: new RegExp(`^/${name}`),
308+
to: path.posix.join(baseUrl, pages[name].filename || `${name}.html`)
309+
}))
310+
return [
311+
...multiPageRewrites,
312+
{ from: /./, to: path.posix.join(baseUrl, 'index.html') }
313+
]
314+
}
315+
305316
module.exports.defaultModes = {
306317
serve: 'development'
307318
}

0 commit comments

Comments
 (0)