historyApiFallback: true 对应的 nginx 配置

这个设置用于自动将404响应跳转到首页入口文件 index.html。

webpack 配置如下:

module.exports = {
  //...
  devServer: {
    historyApiFallback: true
  }
};

部署到服务器上时 nginx 的配置如下:

server {
    listen  80;
    server_name  172.20.47.16;

    location / {
        root /usr/share/nginx/html/console;
        try_files $uri $uri/ /index.html;  # 加上这一行即可
    }

    access_log /var/log/nginx/console_access.log main;
    error_log /var/log/nginx/console_error.log;
}

参考:
https://webpack.js.org/configuration/dev-server/#devserverhistoryapifallback
https://www.cnblogs.com/zph666/p/11468883.html

posted @ 2020-04-13 19:27  KeithTt  阅读(3030)  评论(0编辑  收藏  举报