为 Angular html5mode 配置 Webpack 开发服务器

Configuring the Webpack Dev Server for Angular html5mode

我正在尝试在 Angular 1 应用程序中启用 html5 模式。此模式要求网络服务器对各种路径 return 相同 HTML。在 nginx 中,这是通过为 location 添加一个 try ... index.html 来完成的,这意味着如果 nginx 找不到页面,它总是会故障返回到主 html。

但是,在开发时我没有 nginx,我使用 Webpack 开发服务器来提供页面,并使用后端代理。我如何配置 Webpack 开发服务器以类似的方式运行?

哦,亲爱的。哦亲爱的哦亲爱的哦亲爱的

我扫描了两次文档,只有在发布这个问题后我才找到 historyApiFallback 设置,as described here.

将此添加到设置中:

devServer: {
    historyApiFallback: true,
    proxy: { ... }
}

我把这个问题留在这里,希望它能帮助其他人在将来节省时间。