taro项目打包配置如下:
h5: {
publicPath: "/",
router: {
mode: 'browser',
customRoutes: {
'/pages/index/index': '/index',
'/pages/log/index': '/log'
}
},
// ....
}
问题复现:
运行yarn build:h5,生成index.html,用vscode Live Server启动index.html,静态资源404
搜索github issue得知要部署到服务器上,于是在本地搭建nginx,配置如下
server {
listen 8080;
server_name localhost;
location / {
root /Users/fancy/Documents/myproject/map-web/dist;
index index.html index.htm;
try_files $uri $uri/ /index.html;
}
}
nginx每一句后面要加分号!!
try_files $uri $uri/ /index.html——是为了解决在路由下每次刷新404的问题