方法1:
const http = require('http');const fs = require('fs');var express = require('express');var app = express();app.set('roots', __dirname+'/dist');app.use('/', express.static(app.get('roots')));app.use('*', function (req, res, next) {fs.readFile(app.get('roots')+'/index.html', 'utf-8', (err, content) => {if (err) {console.log('We cannot open "index.htm" file.')}res.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'})res.end(content)})});http.createServer(app).listen(3030,() => {console.log('Server listening on: http://localhost:%s', 3030)});
参考文档:vue HTML5 History 模式 node服务器端的配置
方法2:node 服务器对history模式的支持
使用插件 connect-history-api-fallback
参考文档:https://www.yuque.com/u21575953/ya6syy/amdxmm
