Open Xooone47 opened 1 year ago
up up up
Actually, when createHtmlPlugin is enabled, any route is ignored and only the root path is rendered. This happens even with the public folder.
As a quick test:
Try vite-plugin-simple-html. It has fewer features, but as a result, far less magic required. I developed it specifically to cover my needs while not be affected by this bug, which was a blocker for me migrating to Vite.
Demo
https://codesandbox.io/p/sandbox/vite-plugin-html-redirect-demo-jhjqtn?file=%2Fvite.config.js
Reproduce steps
export default defineConfig({ plugins: [ vue(), createHtmlPlugin({ entry: "/src/main.js", template: "index.html", }), ], server: { cors: true, proxy: { "/api": { target: "https://www.baidu.com", changeOrigin: true, configure: (proxy, _options) => { proxy.on("proxyReq", function (proxyReq, req, res, options) { if (req.url.includes("/api")) { console.log("req.url", req.url); console.log("req.originalUrl", req.originalUrl); console.log("req._parsedUrl", req._parsedUrl); } }); }, }, }, }, });
On the console, we can see the originalUrl that was requested is
/api/login?redirect=mockUrl
, but it becomes/api/login
after being handled by the proxy middleware.And the URL is correct when we click the
Fetch
button to trigger axhr request
.Reason
code
The vite-plugin-html adds a proxy handling rule for
text/html
type request, and usesparsedUrl.pathname
whichdoesn't contain query params
(pic below) as the path to redirect. So the problem occurs when starts adocument
request but thexhr
requests is good.