摘录于https://www.npmjs.com/package/connect-history-api-fallback
安装
npm install --save connect-history-api-fallback
示例
var express = require('express');
var history = require('connect-history-api-fallback');
var app = express();
app.use(history());
参数
Override the index (default /index.html)
history({
index: '/default.html'
});
Override the index when the request url matches a regex pattern.
history({
rewrites: [
{ from: /\/soccer/, to: '/soccer.html'}
]
});
This middleware does not log any information by default. If you wish to activate logging, then you can do so via the verbose option or by specifying a logger function.
history({
verbose: true,
logger: console.log.bind(console)
});
Override the default Accepts: headers that are queried when matching HTML content requests (Default: ['text/html', '/']).
history({
htmlAcceptHeaders: ['text/html', 'application/xhtml+xml']
})