vue3.0 router在history模式下服务器配置问题

1. 打包部署在服务器根目录

  1. 客户端在项目中的vue.config.js 配置
module.exports = {
    publicPath: '/'
}
  1. 服务器配置,以Nginx服务器实例
    1. 爬坑1:通过vue官方文档,我们知道在服务器配置文件中去配置

       location/{try_files$uri $uri/ /index.html;}
      
    2. 但是会弄错去配置哪个文件,我在/conf/nginx.conf中搞了很久都不行,都快要放弃的时候,我看到了conf/vhost/0localhost_80.conf ,然后在这个文件中试了一下,就行了。官方文档没有说明仔细,经常导致掉坑里。

    3. 所以最后,我在conf/vhost/0localhost_80.conf 文件中配置

       location / {
       	index index.php index.html;
       	try_files $uri $uri/ /index.html;在这里插入代码片
       }
      

2. 打包部署在服务器子目录内

在子目录中部署项目需要配置几个地方

  1. 在vue.config.js中配置
module.exports = {
	publicPath: '/web' // web为子目录名称
}
  1. 在router/index.js中配置
const router = createRouter({
    history: createWebHistory('/web'), // web为vue.config.js 配置的子目录,如果在根目录部署不用填
    routes,
});
  1. 在服务器配置conf/vhost/0localhost_80.conf
location /web {  // web为子目录名
	index index.php index.html;
	try_files $uri $uri/ /web/index.html;  //web为子目录名
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值