Express
服务器端解决 History 404
js
npm install --save connect-history-api-fallback
js
let history = require("connect-history-api-fallback");
let express = require("express");
let app = express();
app.use(history());
app.listener(3000, () => {
console.log("serve is running");
});
参数更多的用法
js
// 可选的参数,比如覆盖默认的索引文件:
history({
index: '/default.html'
});
// 当请求url匹配 regex 模式时,重写索引
history({
rewrites: [ rewrites: [
{ from: /\/soccer/, to: '/soccer.html'}{ from: /\/soccer/, to: '/soccer.html'}
] ]
});