history 模式下 vite.config.js 配置 base: './' 路由跳转后无法正确获取到对应 js 、css 文件 #20762
Unanswered
monkeying-boy
asked this question in
Q&A
Replies: 1 comment
-
这个不是vite的问题 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
在使用
pnpm create vue@latest
搭建的项目后,vite.config.ts
配置的base:'./'
然后打包后放在服务器上部署,nginx 配置:在启动 nginx 后访问 www.demo.com/test 首页能够正常访问,但是涉及到
vue-router
跳转后就无法正确访问到了。比如在项目中 配置了 /home 和 /login 两个路由,当访问 www.demo.com/test/home 时页面无法正确访问,打开浏览器发现请求的js 路径是
www.demo.com/test/home/js/index-CrKRtstp.js
而正确的文件路径应该是www.demo.com/test/js/index-CrKRtstp.js
。在项目中我是用
base: './'
这样配置的原因是在前端打包后会在同一个服务器上根据路径不同 部署不同环境的前端项目。比如:www.demo.com/test
和www.demo.com/dev
分别访问的是 测试环境和 开发环境的前端项目。对此有什么比较好的解决方案吗?
Reproduction
"vite": "7.1.3"
Steps to reproduce
No response
System Info
Used Package Manager
pnpm
Logs
No response
Validations
Beta Was this translation helpful? Give feedback.
All reactions