如何告诉 webpack 开发服务器为任何路由提供 index.html [英] How to tell webpack dev server to serve index.html for any route
问题描述
React 路由器允许 React 应用程序处理 /arbitrary/route
.为了让它工作,我需要我的服务器在任何匹配的路由上发送 React 应用程序.
React router allows react apps to handle /arbitrary/route
. In order this to work, I need my server to send the React app on any matched route.
但是 webpack dev server 不处理任意端点.
But webpack dev server doesn't handle arbitrary end points.
这里有一个使用额外快速服务器的解决方案.如何允许webpack-dev-server 允许来自 react-router 的入口点
There is a solution here using additional express server. How to allow for webpack-dev-server to allow entry points from react-router
但我不想启动另一个快速服务器来允许路由匹配.我只想告诉 webpack 开发服务器匹配任何 url 并将我的 react 应用程序发送给我.请.
But I don't want to fire up another express server to allow route matching. I just want to tell webpack dev server to match any url and send me my react app. please.
推荐答案
我找到了包含一个小配置的最简单的解决方案:
I found the easiest solution to include a small config:
devServer: {
port: 3000,
historyApiFallback: {
index: 'index.html'
}
}
我通过访问发现了这个:PUSHSTATE WITH WEBPACK-DEV-SERVER.
I found this by visiting: PUSHSTATE WITH WEBPACK-DEV-SERVER.
这篇关于如何告诉 webpack 开发服务器为任何路由提供 index.html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!