history 主要使用的是 connect-history-api-fallback 库来让单页面应用能通过不同的 URL 正常访问
其实其作用过类似于 nginx 的 rewrite /index.html,只不过 vite 做了另外一个处理,就是如果真的通过 url 找到一个文件了,就不重定向至 /index.html 了
middlewares.use(history({logger: createDebugger('vite:spa-fallback'),// support /dir/ without explicit index.htmlrewrites: [{from: /\/$/,to({ parsedUrl }: any) {const rewritten = parsedUrl.pathname + 'index.html'if (fs.existsSync(path.join(root, rewritten))) {return rewritten} else {return `/index.html`}}}]}))
