React slingshot - 使用 React 路由器子路由时,Webpack 热中间件在 hot-update.json 上返回 404

Jon*_*Lau 4 webpack react-router react-slingshot

我正在为我的 react/redux 应用程序使用 react slingshot starter 项目。当我使用类似的路由时,热重载效果很好,/foo但我发现热重载不适用于/foo/bar. 我没有对开箱即用的 webpack 配置文件进行任何更改,可以在这里找到https://github.com/coryhouse/react-slingshot/blob/master/webpack.config.js

404 GET http://localhost:3004/orders/c344e97ed1fbc2923017.hot-update.json 404 (Not Found)当我有以下路由配置时,我进入了 CreateOrder 组件:

<Route path="/" component={App}>
    <Route path="login" component={Login} />
    <Route path="orders" component={OrderPanel} />
    <Route path="orders/create" component={CreateOrder} />
    <Route path="*" component={NotFoundPage} />
</Route>
Run Code Online (Sandbox Code Playgroud)

但是当我将路径从 orders/create 更改为 just create 时,它​​不会返回 404。

似乎热更新中间件正试图从 /orders 子路由中获取 hot-update.json?

Yan*_*ann 5

只是为了完整性以及任何使用旧版本弹弓遇到此问题的人。这也在issue 75 中提到,并通过替换在此处修复:

publicPath: '',
Run Code Online (Sandbox Code Playgroud)

publicPath: '/',
Run Code Online (Sandbox Code Playgroud)

webpack.config.js

更新:根据 reduckted 的评论,publicPath 必须以斜杠开头和结尾。代替:

publicPath: 'dist/',
Run Code Online (Sandbox Code Playgroud)

publicPath: '/dist/',
Run Code Online (Sandbox Code Playgroud)