-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
transformIndexHtml
hook gets the wrong html filepath when running Multi-Page
#2958
Comments
Hello @yaquawa. Please provide a online reproduction by codesandbox or a minimal GitHub repository. Issues labeled by |
Hi, I have added the reproduction steps. Please take a look at. Thanks. |
I am not sure if this is expected, vite is currently redirected to index.html locally, and the configuration build mentioned in the document https://vitejs.dev/guide/build.html#multi-page-app
|
Hi @anncwb Thanks for replying! |
I second @anncwb. Vite currently performs a simple fallback when the route |
look expects to me vite's documentation need to mention this. |
Some related issues #5757 #7095 |
I'm a bit wary of adding new options, but it does seem like doing so could provide a workaround for this PR. |
you can use const { defineConfig } = require('vite')
module.exports = defineConfig({
plugins: [
{
name: 'rewrite-middleware',
configureServer(serve) {
serve.middlewares.use((req, res, next) => {
if (req.url.startsWith('/nested/')) {
req.url = '/nested/'
}
next()
})
}
}
]
}) so |
I'm having issues with trailing slashes. Using this example, I replaced |
Any updated on this I am also having the redirection issue |
It seems path rewriting does not work with this plugin. vite/packages/vite/src/node/server/middlewares/indexHtml.ts Lines 66 to 116 in 1d6a1eb
|
Looking back, I think this is still expected. Vite default runs in SPA mode, so 404s redirect to |
Describe the bug
transformIndexHtml
hook gets the wrong html filepath when running Multi-Page.Reproduction
Project root directory structure:
in the
transformIndexHtml
hook:Go to
/landing-page/
filename
will be<root>/landing-page/index.html
witch is correct.but, if go to
/landing-page/foo/
filename
will be<root>/index.html
which is the the wrong filename.it really should be
<root>/landing-page/index.html
when the url is subpath of/landing-page/
.Sure I can fix this by add an additional middleware to the ViteDevServer, but it really should detect if it is a Multi-Page, if it is, add the routes for it automatically.
Reproduction
yarn
console.log
to log the ctx.filename, https://github.com/ssr-glue/vite-plugin/blob/755371d940fbea6365a38cab0f9c03e868f0db91/packages/vite-plugin/src/plugin.ts#L67-L78 then runyarn build
packages/playground/vue
runyarn dev
The text was updated successfully, but these errors were encountered: