vite打包时发布时,放在服务器的二级目录中

方式一 hash模式

如果我们的站点根目录为 public , 我们访问的时候使用的是 http://www.abc.com/ 访问到了站点的根目当,现在我们要访问 http://www.abc.com/mysite/#/

配置如下

  1. 修改 vite.config.js base:"/mysite/"
  2. 修改 router中的配置

    上面的步骤完成,就可以 把 build的文件,放在 public/mysite/ 的目录下, 使用 http://www.abc.com/mysite/#/就可以访问了

方式二 history模式

  1. 同样是修改 vite.config.js 的base 属性

  2. 在history模式下, 如果用户刷新页面会出问题,所以我们在要 nginx上配置一下 location
config 复制代码
location /mysite/ {
	try_files $uri $uri/  /mysite/index.html
}

说明一下, hash 模式下的访问路径是:http://www.abc.com/mysite/index.html

history 模式下的访问路径是:http://www.abc.com/mysite/


在history模式下,使用 http://www.abc.com/mysite/index.html 来访问是错误的

相关推荐
LH_R21 小时前
OneTerm开源堡垒机实战(四):访问授权与安全管控
运维·后端·安全
Raymond运维1 天前
MariaDB源码编译安装(二)
运维·数据库·mariadb
JuiceFS2 天前
从 MLPerf Storage v2.0 看 AI 训练中的存储性能与扩展能力
运维·后端
chen9452 天前
mysql 3节点mgr集群部署
运维·后端
LH_R2 天前
OneTerm开源堡垒机实战(三):功能扩展与效率提升
运维·后端·安全
dessler2 天前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
少妇的美梦3 天前
logstash教程
运维
chen9453 天前
k8s集群部署vector日志采集器
运维
chen9453 天前
aws ec2部署harbor,使用s3存储
运维
christine-rr3 天前
linux常用命令(4)——压缩命令
linux·服务器·redis