React 部署nginx二級目錄(子目錄)

一、背景描述:

react打包出來的文件,想部署在 如 https://www.abc.com/webapp下,

本項目使用的是history:hash 模式,

如果使用的是history:browser ,可參考該大神的文章https://www.freesion.com/article/5887723973/

二、解決方法

1、修改/添加 配置

// package.json
"homepage":"."

2、在每一個index.html文件添加

# webapp 是你自己文件夾的名稱
<base href="/webapp/">

3、將打包後的文件丟到服務器

4、nginx添加配置,重啓

location /webapp/ {
      index  index.html index.htm;
}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章