taro项目打包配置如下:

    1. h5: {
    2. publicPath: "/",
    3. router: {
    4. mode: 'browser',
    5. customRoutes: {
    6. '/pages/index/index': '/index',
    7. '/pages/log/index': '/log'
    8. }
    9. },
    10. // ....
    11. }

    问题复现:
    运行yarn build:h5,生成index.html,用vscode Live Server启动index.html,静态资源404
    搜索github issue得知要部署到服务器上,于是在本地搭建nginx,配置如下

    1. server {
    2. listen 8080;
    3. server_name localhost;
    4. location / {
    5. root /Users/fancy/Documents/myproject/map-web/dist;
    6. index index.html index.htm;
    7. try_files $uri $uri/ /index.html;
    8. }
    9. }

    nginx每一句后面要加分号!!
    try_files $uri $uri/ /index.html——是为了解决在路由下每次刷新404的问题