Replies: 1 comment 3 replies
-
Such rewriting is not supported out-of-the-box on Vite, but probably you can try writing middleware as plugin, maybe something like this: export default defineConfig({
plugins: [
{
name: 'my-spa-fallback',
configureServer(server) {
server.middlewares.use((req, res, next) => {
const url = new URL(req.url, "http://localhost");
if (url.pathname.startsWith("/app/")) {
req.url = "/app.html"
}
if (url.pathname.startsWith("/arm/")) {
req.url = "/arm.html"
}
next();
});
}
}
]
}) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm migrating a project from Webpack to Vite and trying to replicate this Webpack devServer configuration:
I attempted the following Vite configuration:
With this, I can open /app and /arm, but navigating to /app/login results in a "No webpage found" error.

What I Need:
I want Vite to behave like Webpack's historyApiFallback, ensuring:
/app loads app.html,
/arm loads arm.html,
Any subroutes like /app/login should still serve app.html,
Any subroutes like /arm/settings should serve arm.html.
My Research:
I've looked into Vite's server options, specifically server.middlewareMode, but I’m not sure how to properly rewrite requests for different contexts.
Has anyone done something similar in Vite? How can I configure Vite's dev server to handle this kind of routing logic??
Beta Was this translation helpful? Give feedback.
All reactions