如果nginx中配置了location规则,在vue页面中路由跳转的时候会将location的前缀刷掉怎么解决?
如果nginx中配置了location,在vue页面中路由跳转的时候会将location的前缀刷掉怎么处理?例如在nginx的配置里:
server{
listen xxxx:xxxx;
# 这里匹配的规则是 /mydisk/
location /mydisk/ {
root /var/www/mydisk/web;
index index.html;
}
}
vue项目中,路由的规则:
const routes = [
{
path: '/',
name: 'filelist',
component: FileListCom,
},
{
path: '/upload',
name: 'fileupload',
component: UploadCom
}
]
菜单:
<el-menu router default-active="/mydisk/" mode="horizontal">
<el-menu-item index="/">
A
</el-menu-item>
<el-menu-item index="/upload">
B
</el-menu-item>
</el-menu>
把项目打包发布后,访问http://xxxx:xxxx/mydisk/
,这时候访问的页面是正常的,但是点击菜单A后,地址就变成了http://xxxx:xxxx/
(或者点击菜单B后,地址变成http://xxxx:xxxx/upload
),这样页面资源就请求不到了我现在的解决办法是直接在vue路由规则里写死前缀/mydisk/
,但是应该有更规范的办法吧,望大家赐教
回复
1个回答

test
2024-06-30
在 vue.config.js 中设置 publicPath 选项,将 publicPath 设置为 ‘/mydisk’,然后重新打包
https://blog.csdn.net/qq_27575627/article/details/130215619
回复

适合作为回答的
- 经过验证的有效解决办法
- 自己的经验指引,对解决问题有帮助
- 遵循 Markdown 语法排版,代码语义正确
不该作为回答的
- 询问内容细节或回复楼层
- 与题目无关的内容
- “赞”“顶”“同问”“看手册”“解决了没”等毫无意义的内容