【发布时间】:2018-04-26 15:58:55
【问题描述】:
Sample repo demonstrating the issue is here.
我正在尝试设置 webpack 开发服务器,以便:
-
/的请求由public/landing.html(静态登录页面)处理 - 我的 React 应用会处理对其他任何内容的请求
使用create-react-app 和based on webpack-dev-server's options,我将webpackDevServer.config.js 设置如下:
historyApiFallback: {
// Paths with dots should still use the history fallback.
// See https://github.com/facebookincubator/create-react-app/issues/387.
disableDotRule: true,
rewrites: [
// shows views/landing.html as the landing page
{ from: /^\/$/, to: 'landing.html' },
// shows views/subpage.html for all routes starting with /subpage
{ from: /^\/subpage/, to: 'subpage.html' },
// shows views/404.html on all other pages
{ from: /./, to: '404.html' },
],
},
当我启动 webpack 时,我看到的是:
- 对
/subpage的请求被正确路由到subpage.html - 对
/foo的请求被正确路由到404.html。最终,这些将由我的 React 应用处理。 - 对
/的请求被错误地路由到我的 React 应用程序。
如何让landing.html 回复/ 的请求?
【问题讨论】:
标签: reactjs webpack webpack-dev-server create-react-app webpack-dev-middleware